﻿#include "ProjectDlg.h"
#include "ui_ProjectDlg.h"
#include "QAlgoFactory.h"
#include <QPushButton>
#include "MyLabel.h"
#include <QFileDialog.h>
#include <QDesktopServices>
#include "Imgtfc.h"
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include "pgf.h"
#include <QStatusBar>
#include "Igv.h"
#include "ProjectData.h"
#include <map>
#include "CParaContain.h"
#include "SocketCommServer.h"
#include "mtp.h"
#include"Global.h"
#include "Pgv.h"
#include "QSimulateCam.h"
#include "mss.h"
#include "IStateDlg.h"
#include "Pgv.h"
#include "QILightCtrl.h"
#include "IVisionCtrlDlg.h"
#include "QCameraHK.h"
#include "QICamera.h"
#include "QCameraImp.h"
#include <functional>
#include "DispInfoDlg.h"
#include "IMenuManager.h"
#include <fstream>
#include <sstream>
#include <QDateTime>
#include <QTime>
#include "ui_MesDlg.h"
#include "QWorkRateDlg.h"
#include "QDrawDlg.h"
#include "ui_DispInfoDlg.h"


#pragma execution_character_set("utf-8")
using namespace std;



Q_DECLARE_METATYPE(StFixedData)

ProjectDlg::ProjectDlg(QWidget *parent)
	: MyAlgoDialog(parent)
	,pSimulateCam(pgf::gsSimulateCam())
{
	qRegisterMetaType<StFixedData>("StFixedData");
	//m_pProjectDB = mksptr<DataBase>();
	LoadTranslateFile();
	ui = new Ui::ProjectDlg();
	ui->setupUi(this);
	m_pTabPara = ui->Tab_Para;
	m_pThis = this;
	m_AlgoName = PROJECT_NAME;
	gthpool = new ThreadPool();
	gthpool->CreateThread(10);
	gthpool->RegNotEnoughThreadEvent(OnNotEnoughThreadEventHandle_cb, this);

	InitVecData();
	InitProjectFilePath();
	if (m_pSktLinkMaster == nullptr)
	{
		//m_pSktLinkMaster = new SocketCommServer();
	}
	if (m_pMaster == nullptr)
	{
		//m_pMaster = new ModbusMaster();
	}
	if (m_pSktLinkMaster == nullptr)
	{
		m_pSktLinkMaster = new SocketLinkMaster();
	}
	ReadProjectIni();
	ui->radio_lockOffset->setChecked(m_bLockOffset);
	m_pMesData = new MesData(this);
	InitWindFromConstructor();
	connection();

	ConnectCmd();
	connectLambda();
	std::string temp = Pgv::getHalconDirPath().tostr() + "/Running"+ m_ProductType.tostr()+ ".hdev";
	m_hdev = new Hdev();
	m_hdev->InitHdevFullPath(temp.data());
	InitProjectPara();
	g_pMesDlg = new MesDlg((QWidget*)pgf::GetMainWinPtr());
	g_pMesDlg->m_pMesData = m_pMesData;
	g_pMesDlg->m_pMesData->m_pflexMesDlg = g_pMesDlg;
	g_pMesDlg->m_pRingInspectionDlg = this;
	g_pMesDlg->OnBtnRefresh();
	g_pMesDlg->m_ipAddress = GetmtfInstance()->GetNetCardIp(g_pMesDlg->m_MacAddr);
	m_StartDateTime = QDateTime::currentDateTime();
	CheckCurrentTime();
	CleanUpRubbishDocuments();
	ReadWarningInfo();
	m_pTabPara->setCurrentTab("tab_camera");

    if(m_pWorkRateDlg)	m_pWorkRateDlg->DrawAllChart();//OEE图表

	disconnect(m_pDispInfoDlg->ui->cbx_product, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged), this, &ProjectDlg::OnRingTypeChanged);
	m_pDispInfoDlg->ui->cbx_product->setCurrentText(m_ProductType);
	connect(m_pDispInfoDlg->ui->cbx_product, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged), this, &ProjectDlg::OnRingTypeChanged);
	ui->comboBox_RingType->setDisabled(true);

	m_pProjectDB = nullptr;
	m_pProjectDB = mksptr<DataBase>(m_ProductType);
	InitTableFromDB();

	if (m_ProductType != "Manual")
	{
		m_pDispInfoDlg->m_pBtnDraw->hide();
	}
	else
	{
		m_pDispInfoDlg->m_pBtnDraw->show();
	}

}

void ProjectDlg::OnRingTypeChanged(const QString& text)
{
	m_ProductType = text;
	if (m_ProductType != "Manual")
	{
		m_pDispInfoDlg->m_pBtnDraw->hide();
	}
	else
	{
		m_pDispInfoDlg->m_pBtnDraw->show();
	}
	try
	{
		delete m_hdev;
		m_hdev = nullptr;
		ClearDlModel(m_DLModelHandle);
		ClearShapeModel(m_DeformationModelID);
	}
	catch (...)
	{
		MessageBoxTip("资源清理出错！");
		return;
	}

	std::string temp = Pgv::getHalconDirPath().tostr() + "/Running" + m_ProductType.tostr() + ".hdev";
	m_hdev = new Hdev();
	m_hdev->InitHdevFullPath(temp.data());
	LoadCalibFile();

	GetmtfInstance()->WriteInIFileStr("setting", "ProductType", m_ProductType, m_ProjectiniPath);
	//m_pDispInfoDlg->m_pLabelDisp->setText("Product：" + m_ProductType);
	disconnect(m_pDispInfoDlg->ui->cbx_product, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged), this, &ProjectDlg::OnRingTypeChanged);
	m_pDispInfoDlg->ui->cbx_product->setCurrentText(m_ProductType);
	connect(m_pDispInfoDlg->ui->cbx_product, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged), this, &ProjectDlg::OnRingTypeChanged);
	
	
	m_pProjectDB = nullptr;
	m_pProjectDB = mksptr<DataBase>(m_ProductType);
	InitTableFromDB();
	
	
	MessageBoxTip("产品型号切换完成！");
	return;
}


ProjectDlg::~ProjectDlg()
{
	delete m_hdev;
	//m_pSktLinkMaster->m_bExit = true;
	//mSleep(100);
	//delete m_pSktLinkMaster;
	//m_pSktLinkMaster = nullptr;
	delete 	g_pMesDlg;
	g_pMesDlg = nullptr;
	delete m_pMesData;
	m_pMesData = nullptr;
	delete ui;
}

void ProjectDlg::LoadTranslateFile()
{
	sptr qtTranslator = mksptr<QTranslator>();
	QString path = QApplication::applicationDirPath() + "/project_language_en.qm";
	if (qtTranslator->load(path))
	{
		QApplication::installTranslator(qtTranslator.get());
	}
}

void ProjectDlg::Register()
{
	QAlgoFactory::GetInstance()->Register("ProjectDlg", CreatObj);
}

std::shared_ptr<MyDialog> ProjectDlg::CreatObj()
{
	return std::make_shared<ProjectDlg>((QWidget*)pgf::GetMainWinPtr());
}

//void ProjectDlg::AutoInitParaFromFlow()
//{
//	m_pflow->m_NeedWriteDataAlgoDlgMap[m_AlgoName] = this;
//	if (m_pflow->IsNewFlow()) return;
//	m_pflow->ReadDataFromPara(this);
//	DefaultPathConvert();
//	InitWindFromFlow();
//	ui->textBrowser_CmdPath->setText(m_PlcCmdPath);
//	if (!m_PlcCmdPath.isEmpty()) ReadCmdPlc();
//}

void ProjectDlg::AutoInitParaFromFlow()
{
	m_pflow->m_NeedWriteDataAlgoDlgMap[m_AlgoName] = this;
	if (m_pflow->IsNewFlow()) return;
	InitParaFromDB();
}

void ProjectDlg::InitParaFromDB()
{
	ReadMemberVariablesFromDB();
	//InitTableFromDB();//Construct时已经更新
	//InitCameraPara();
	InitLight();
	DefaultPathConvert();
	ui->textBrowser_CmdPath->setText(m_PlcCmdPath);
	if (!m_PlcCmdPath.isEmpty()) ReadCmdPlc();
}

void ProjectDlg::ReadMemberVariablesFromDB()
{
   m_PlcCmdPath = GetmtfInstance()->QuerySingleValue2QString("conn1","成员变量表","string","变量名","m_PlcCmdPath",true);
}

void ProjectDlg::WriteMemberVariables2DB()
{
  GetmtfInstance()->UpdateSingleValue("conn1", "成员变量表", "string",m_PlcCmdPath, "变量名", "m_PlcCmdPath","1,1");
  MessageBoxTip("筛环机参数保存成功！");
}

void ProjectDlg::RegistGlobalCallBack()
{
	pgf::AddItemToolList(ProjectDlg::ProjectAddItemToToolLIst);//添加项目
	pgf::RegAutoCreateAlgoFun(ProjectDlg::ProjectAutoCreateAlgo);
	pgf::RegDispOrCreateDlgFun(ProjectDlg::ProjectDispOrCreateDlg);
	pgf::RegWriteDataFun(ProjectDlg::ProjectWriteDataFun);
	pgf::GetSetRobotCoorByComm()=GetRobotCoorByComm_cb;
	pgf::GetSetRelativeMoveFun() = RelativeMoveFun_cb;


	pgf::RegInitStatusBarFun(DispVersion_cb);
	if (m_pDispInfoDlg==nullptr) m_pDispInfoDlg = new DispInfoDlg();
	pgf::RegCustomDlg(tr("信息"),m_pDispInfoDlg);
	pgf::RegLogDispParaFun(DispInfoDlg::logDisp, "mVisonAppender", m_pDispInfoDlg);
	pgf::RegCameraLinkStateFun(CameraLinkState_cb);
	IMenuManager::RegShowDataInteractionDlgFun(OnDataInteraction_cb);
	//pgf::GetSetReadImgInfoFun() = GetImgInfo_cb;
	pgf::GetSetRotateCenterOperateDBFun() = WriteRotateCenter2DB_cb;
	pgf::GetSetCaliperToolOpDBFun() = WriteStdPos2DB_cb;
	pgf::GetSetDispDlgTabWidgetFun() = DispOEEInfo_cb;//OEE

}

void ProjectDlg::ProjectAddItemToToolLIst(MyTreeWidget* pTreeWidget)
{
	//项目
	QTreeWidgetItem* root = pTreeWidget->AddTreeRoot("项目");
	pTreeWidget->AddTreeNode(root, PROJECT_NAME);
}

void ProjectDlg::ProjectAutoCreateAlgo(QString strSeletAlgo, std::string& AlgoName, std::shared_ptr<QFlowsBase>& pflow, void* pObj)
{
	if (strSeletAlgo != PROJECT_NAME) return;
	if (pObj != nullptr)
	{
		AutoCreateAlgoDlgByLoadFlow<ProjectDlg>(AlgoName, "ProjectDlg", pflow);
	}
}

void  ProjectDlg::ProjectDispOrCreateDlg(QString strSeletAlgo, void* pObj)
{
	if (strSeletAlgo != PROJECT_NAME) return;
	auto p = DispOrNewCreateAlgoDlg<ProjectDlg>(strSeletAlgo, "ProjectDlg");
}

void ProjectDlg::ProjectWriteDataFun(std::map<QString, MyAlgoDialog*>& WriteDataFunMap, CParaContain& para)
{
	if (WriteDataFunMap[PROJECT_NAME] != nullptr)
	{
		CDataBase* ptr = new ProjectData();
		ptr->writeData(WriteDataFunMap[PROJECT_NAME]);
		para.m_VecDataPtr.push_back(ptr);
		m_pThis->WriteMemberVariables2DB();
	}
}

int ProjectDlg::GetRobotCoorByComm_cb(QPointF* pointValue, int* robotID, int* R_AxisNo, int* ImgProcID, int* PointIndex, double* R, double* Z)
{
	m_isGetRobotPos = false;
	if (m_pSktLinkMaster == nullptr) return -1;
	//m_pSktLinkMaster->GetAbsPos(*robotID, *R_AxisNo);
	bool bCheckTimeOut = false;
	auto starttime = GetmtfInstance()->GetTimeNow();
	while (!m_isGetRobotPos)
	{
		QCoreApplication::processEvents();
		auto endtime = GetmtfInstance()->GetTimeNow();	
		if (GetmtfInstance()->durationTime(endtime,starttime,TimeType::second) > 5)
		{
			MessageBoxTip("获取机械手位置超时！");
			LOG_DEBUG(glogger, MultUtf82Mult2("获取机械手位置超时！"));
			bCheckTimeOut = true;
			break;
		}
	}
	if (bCheckTimeOut)
	{
		(*pointValue).rx() = 999999;
		(*pointValue).ry() = 999999;
		*R= 999999;
		return -2;
	}
	else
	{
		(*pointValue).rx() = m_GetRobotPos.x;
		(*pointValue).ry() = m_GetRobotPos.y;
		*R = m_GetRobotPos.R/1000;//下位机*1000发出来
	}
	m_isGetRobotPos = false;
	return 0;
}
           
void ProjectDlg::RelativeMoveFun_cb(int* robotID, int* R_AxisNo, double* x, double* y, double* Degree, int* z, int* pawStatus)
{
	if (m_pSktLinkMaster == nullptr) return ;
	//m_pSktLinkMaster->RelativeMove(*robotID, *R_AxisNo,*x,*y,(*Degree)*1000);

}

void ProjectDlg::InitVecData()
{
	for (int i = 0; i < 4; i++)
	{
		m_bWillPhoto[i] = false;
		m_bCameraTriggred[i] = false;
		m_CameraImg[i] = mksptr<HObject>();
	}

	ShapePara ShapeParaTemp;
	m_ShapeParaBC.push_back(ShapeParaTemp);

	DataInfo temp;
	for (int i = 0; i < 3; i++)
	{
		m_ManualBC.push_back(temp);// //3测量结果BC，高度，宽度，角度
	}

	for (int i = 0; i < 4; i++)
	{
		m_GroupImg[i] = mksptr<HObject>();
		m_DutImgRoi[i] = mksptr<HObject>();
		GenEmptyObj(m_DutImgRoi[i].get());// Create an empty object tuple.
	}
	for (int i=0;i<12;i++)
	{
		m_NozzleImgRoi[i] = mksptr<HObject>();
		m_ResultRegion[i] = mksptr<HObject>();
		m_Cross[i] = mksptr<HObject>();
		m_ModelContourXld[i] = mksptr<HObject>();
		m_SearchContourXld[i] = mksptr<HObject>();
		m_PointCrossXld[i] = mksptr<HObject>();
	}

	m_SecondScanImg= mksptr<HObject>();
	m_FrontROI= mksptr<HObject>();

	AppearencePara  temp2;

	m_RotateCenterImg.clear();
	m_StandOffsetLoadRobot.clear();
	//m_StdRobotPos.clear();
	m_StandImagePos.clear();
	m_LightIntensity.clear();
	m_NozzleHight.clear();
	m_AppearencePara.clear();

	for (int i = 0; i <6; i++)
	{
		m_StandOffsetLoadRobot.push_back(temp);	
		m_NozzlePosRobot.push_back(temp);
		m_CameraPosRobot.push_back(temp);
	}
	for (int i = 0; i < 6; i++)
	{
		m_LightIntensity.push_back(temp);
	}
	for (int i = 0; i < 12; i++)//取料6个，放料6个，共12个
	{
		m_RotateCenterImg.push_back(temp);	
	}
	for (int i = 0; i < 2; i++)
	{
		m_AppearencePara.push_back(temp2);//2组数据：边缘和正面,
		m_Gray.Append(0);
		m_Len.Append(0);
		m_Width.Append(0);
		m_Area.Append(0);
		m_NozzleHight.push_back(temp);
	}

	for (int i = 0; i < 30; i++)
	{
		m_StandImagePos.push_back(temp);//24载盘标准图像位置,+6个中转位
		m_slotImgPos.push_back(temp);
	}

	for (int i = 0; i < 4; i++)//翘曲2个，正面1个，反面1个，共4个
	{
		m_CameraPara.push_back(temp); //翘曲2个，正面1个，反面1个，共4个
		m_ControlPara.push_back(temp);
	}

	for (int i = 0; i < 6; i++)
	{
		m_NozzleMarkPos.push_back(temp);//6个吸嘴位置图像坐标
		m_UpCamera2NozzleOffsetWs.push_back(temp);//上相机到6个吸嘴的距离(世界坐标)
	    m_UpCamera2NozzleOffsetBCWs.push_back(temp);//上相机到6个吸嘴的距离的补偿(世界坐标)

	}
}

void ProjectDlg::InitProjectFilePath()
{
	Pgv::getAppFilePath() = GetmtfInstance()->CreateInnerFolder(0, "DataFile/"+gProjectFolder+"/File");
	Pgv::getHalconDirPath()= GetmtfInstance()->CreateInnerFolder(0, "DataFile/"+gProjectFolder+"/File/Hdev");
	Pgv::getFlowDataDirPath() = GetmtfInstance()->CreateInnerFolder(0, "DataFile/"+gProjectFolder+"/File/FlowData");
	Pgv::getModelFileDirPath() = GetmtfInstance()->CreateInnerFolder(0, "DataFile/"+gProjectFolder+"/File/Model");
	Pgv::getJsonFileDirPath() = GetmtfInstance()->CreateInnerFolder(0, "DataFile/"+gProjectFolder+"/File/JsonFile");
	Pgv::getCalibFileDirPath()= GetmtfInstance()->CreateInnerFolder(0, "DataFile/"+gProjectFolder+"/File/Calibrate");
	Pgv::get2DCodeHandlePath() = GetmtfInstance()->CreateInnerFolder(0, "DataFile/"+gProjectFolder+"/File/2DCodeModel");
	Pgv::getPlcCmdDirPath() = GetmtfInstance()->CreateInnerFolder(0, "DataFile/"+gProjectFolder+"/File/PlcCmd");
	Pgv::getMetrologyHandleFileDirPath() = GetmtfInstance()->CreateInnerFolder(0, "DataFile/"+gProjectFolder+"/File/Metrology");
	Pgv::getCameraCalibFilePath() = GetmtfInstance()->CreateInnerFolder(0, "DataFile/"+gProjectFolder+"/File/CameraCalibFile");
	Pgv::getCameraCalibFilePath() = GetmtfInstance()->CreateInnerFolder(0, "DataFile/" + gProjectFolder + "/File/DeepLearn");

	m_ProjectiniPath = GetmtfInstance()->CreateInnerFile(0, "DataFile/"+gProjectFolder+"/ini", gProjectFolder+".ini");

	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	m_PictureFolderPath= GetmtfInstance()->CreateExteriorFolder("D:/Data/" + gProjectFolder + "Data/Picture");
	m_PlcLogDataFolderPath= GetmtfInstance()->CreateExteriorFolder("D:/Data/" + gProjectFolder + "Data/PLCWarning");
	m_WorkRateFolderPath = GetmtfInstance()->CreateExteriorFolder("D:/Data/" + gProjectFolder + "Data/WorkRate");
	//////////
	m_CsvFolderPath = GetmtfInstance()->CreateExteriorFolder("D:/Data/" + gProjectFolder + "Data/Csv");
	GetmtfInstance()->CreateExteriorFolder("D:/Data/" + gProjectFolder + "Data/DeepLearn/model");
}

void ProjectDlg::ReadProjectIni()
{
	QString temp = GetmtfInstance()->ReadInIFileStr("setting", "m_bShieldAppearance", m_ProjectiniPath);
  if (temp=="true")
  {
	  m_bShieldAppearance = true;
  } 
  else
  {
	  m_bShieldAppearance = false;
  }
  ui->radio_ShieldAppearance->setChecked(m_bShieldAppearance);


 temp = GetmtfInstance()->ReadInIFileStr("setting", "m_bShieldDeformation", m_ProjectiniPath);
  if (temp == "true")
  {
	  m_bShieldDeformation = true;
  }
  else
  {
	  m_bShieldDeformation = false;
  }
  ui->radio_shieldDeformation->setChecked(m_bShieldDeformation);

 temp = GetmtfInstance()->ReadInIFileStr("setting", "m_bShieldHight", m_ProjectiniPath);
  if (temp == "true")
  {
	  m_bShieldHight = true;
  }
  else
  {
	  m_bShieldHight = false;
  }
  ui->radio_shieldHight->setChecked(m_bShieldHight);


  temp = GetmtfInstance()->ReadInIFileStr("setting", "m_bShieldWarPage", m_ProjectiniPath);
  if (temp == "true")
  {
	  m_bShieldWarPage = true;
  }
  else
  {
	  m_bShieldWarPage = false;
  }
  ui->radio_shieldWarPage->setChecked(m_bShieldWarPage);
   temp = GetmtfInstance()->ReadInIFileStr("setting", "m_Days", m_ProjectiniPath);
   m_Days = temp.toInt();

  temp = GetmtfInstance()->ReadInIFileStr("setting", "m_bCheckTime", m_ProjectiniPath);
  if (temp == "true")m_bCheckTime = true;
  else m_bCheckTime = false;

  m_CheckTime[0]= GetmtfInstance()->ReadInIFileStr("setting", "CheckTime_0", m_ProjectiniPath);
  m_CheckTime[1] = GetmtfInstance()->ReadInIFileStr("setting", "CheckTime_1", m_ProjectiniPath);

  ui->radio_SaveOkPic->setChecked(m_bSaveOkPic);
  ui->radio_SaveNGPic->setChecked(m_bSaveNGPic);

  //temp = GetmtfInstance()->ReadInIFileStr("setting", "m_bAlwaysBright", m_ProjectiniPath);
  //if (temp == "true") m_bAlwaysBright = true, ui->radio_TriggerTest->setChecked(m_bAlwaysBright);
  //else m_bAlwaysBright = false;


  temp = GetmtfInstance()->ReadInIFileStr("setting", "Light_1_Channel", m_ProjectiniPath);
  m_vecLightChannel.push_back(temp.toInt());
  temp = GetmtfInstance()->ReadInIFileStr("setting", "Light_2_Channel", m_ProjectiniPath);
  m_vecLightChannel.push_back(temp.toInt());
  temp = GetmtfInstance()->ReadInIFileStr("setting", "Light_3_Channel", m_ProjectiniPath);
  m_vecLightChannel.push_back(temp.toInt());
  temp = GetmtfInstance()->ReadInIFileStr("setting", "Light_4_Channel", m_ProjectiniPath);
  m_vecLightChannel.push_back(temp.toInt());

  temp = GetmtfInstance()->ReadInIFileStr("count", "output", m_ProjectiniPath);
  m_pDispInfoDlg->m_output = temp.toInt();
  m_pDispInfoDlg->m_pRingInspectionDlg = this;
  m_pDispInfoDlg->ShowCountInfo(m_pDispInfoDlg->m_output, m_pDispInfoDlg->m_uphCount);

  temp = GetmtfInstance()->ReadInIFileStr("SERVER_IP", "IP", m_ProjectiniPath);
  m_pSktLinkMaster->m_ServerIp = temp;
  temp = GetmtfInstance()->ReadInIFileStr("SERVER_IP", "Port", m_ProjectiniPath);
  m_pSktLinkMaster->m_Port= temp.toInt();

  temp = GetmtfInstance()->ReadInIFileStr("setting", "ProductType", m_ProjectiniPath);
  m_ProductType = temp;

}

void ProjectDlg::showEvent(QShowEvent* event)
{

	return;
}

void ProjectDlg::CheckCurrentTime()
{
	auto fun = [=] {
		int day,hour, minute, second;//倒计时时长
		int curday, curhour, curminute, cursecond;//当前时间点

		bool bReset = false;
		bool bFinishLastWrite = false;
		bool bFirst = true;
		QString ConnName = QTime::currentTime().toString("hhmmsszzz");
		m_pProjectDB->CreateProjectDataConnection(ConnName);


		while (m_bCheckTime)
		{
			QDateTime curDateTime = QDateTime::currentDateTime();
			QDate curDate = curDateTime.date();
			QTime curTime = curDateTime.time();
			curhour = curTime.hour();
			curminute = curTime.minute();
			cursecond = curTime.second();

			bool res = GetmtfInstance()->CheckCurrentTimeRange(m_CheckTime[0], m_CheckTime[1]);
			if (res)//白班
			{
				m_isDayShift = true;
				GetmtfInstance()->CurrentTimeToFutureTime(m_CheckTime[1], day, hour, minute, second);
				QString text = QString("当前白班，距离白班结束还剩：%1 天 %2 时 %3 分 %4 秒 ").arg(day).arg(hour).arg(minute).arg(second);
				LOG_DEBUG(glogger, MultUtf82Mult(text));
				if (((hour == 11) && (minute == 59) && ((50 <= second)) && (second <= 59)) || bFirst)
				{
					if (bFirst)
					{
						bFirst = false;
						if (GetmtfInstance()->CheckCurrentTimeRange("00:00:00", m_CheckTime[0]))
						{
							curDate = curDate.addDays(-1);
						}
						m_pProjectDB->GetSetWorkRateCurTableName() = "DayWorkRate_" + curDate.toString("yyyy_MM_dd");
						m_pProjectDB->GetSetLogCurTableName() = "DayLog_" + curDate.toString("yyyy_MM_dd");
						GetSetTableName() = curDate.toString("yyyy_MM_dd") + "_Day";
						WriteWorkRateCsvData(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, m_pDispInfoDlg->m_output, 0, 0, 0, 0, 0);
						m_pProjectDB->WriteWorkRateDB(ConnName,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, m_pDispInfoDlg->m_output, 0, 0, 0, 0, 0);
						emit m_pWorkRateDlg->postInitCbxShift();
						LOG_DEBUG(glogger, MultUtf82Mult2("白班启动时写入"));
					}
					else {
						m_pProjectDB->GetSetWorkRateCurTableName() = "DayWorkRate_" + curDate.toString("yyyy_MM_dd");
						m_pProjectDB->GetSetLogCurTableName() = "DayLog_" + curDate.toString("yyyy_MM_dd");
						GetSetTableName() = curDate.toString("yyyy_MM_dd") + "_Day";
						LOG_DEBUG(glogger, MultUtf82Mult2("换成白班表头"));
					}
				}
				else if (((hour == 12) && (minute == 0) && ((0 <= second)) && (second <= 5)))
				{
					m_pProjectDB->GetSetWorkRateCurTableName() = "DayWorkRate_" + curDate.toString("yyyy_MM_dd");
					m_pProjectDB->GetSetLogCurTableName() = "DayLog_" + curDate.toString("yyyy_MM_dd");
					GetSetTableName() = curDate.toString("yyyy_MM_dd") + "_Day";
					LOG_DEBUG(glogger, MultUtf82Mult2("换成白班表头2"));
				}
			}
			else //晚班
			{
				m_isDayShift = false;
				GetmtfInstance()->CurrentTimeToFutureTime(m_CheckTime[0], day, hour, minute, second);
				QString text = QString("当前晚班，距离晚班结束还剩：%1 天 %2 时 %3 分 %4 秒 ").arg(day).arg(hour).arg(minute).arg(second);
				LOG_DEBUG(glogger, MultUtf82Mult(text));
																
				if (((hour == 11) && (minute == 59) && ((50 <= second)) && (second <= 59))  || bFirst)
				{
					if (bFirst)
					{
						bFirst = false;
						if (GetmtfInstance()->CheckCurrentTimeRange("00:00:00", m_CheckTime[0]))
						{
							curDate = curDate.addDays(-1);
						}
						m_pProjectDB->GetSetWorkRateCurTableName() = "NightWorkRate_" + curDate.toString("yyyy_MM_dd");
						m_pProjectDB->GetSetLogCurTableName() = "NightLog_" + curDate.toString("yyyy_MM_dd");
						GetSetTableName() = curDate.toString("yyyy_MM_dd") + "_Night";

						WriteWorkRateCsvData(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, m_pDispInfoDlg->m_output, 0, 0, 0, 0, 0);
						m_pProjectDB->WriteWorkRateDB(ConnName,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, m_pDispInfoDlg->m_output, 0, 0, 0, 0, 0);
						emit m_pWorkRateDlg->postInitCbxShift();
						LOG_DEBUG(glogger, MultUtf82Mult2("晚班启动时写入"));
					}
					else {
						m_pProjectDB->GetSetWorkRateCurTableName() = "NightWorkRate_" + curDate.toString("yyyy_MM_dd");
						m_pProjectDB->GetSetLogCurTableName() = "NightLog_" + curDate.toString("yyyy_MM_dd");
						GetSetTableName() = curDate.toString("yyyy_MM_dd") + "_Night";
						LOG_DEBUG(glogger, MultUtf82Mult2("换成晚班表头"));
					}
				}
				else if (((hour == 12) && (minute == 0) && ((0 <= second)) && (second <= 5)))
				{
					m_pProjectDB->GetSetWorkRateCurTableName() = "NightWorkRate_" + curDate.toString("yyyy_MM_dd");
					m_pProjectDB->GetSetLogCurTableName() = "NightLog_" + curDate.toString("yyyy_MM_dd");
					GetSetTableName() = curDate.toString("yyyy_MM_dd") + "_Night";
					LOG_DEBUG(glogger, MultUtf82Mult2("换成晚班表头2"));
				}
			}

			if (((hour == 11) && (minute == 59) && ((50 <= second)) && (second <= 59)) || bFinishLastWrite)//每班起点，第一次				
			{
				bFinishLastWrite = false;

				if (bReset) { goto label_1; }
				bReset = true;
				//总数据===============================================================================
				m_pDispInfoDlg->m_TotalWorkTime = 0;
				m_pDispInfoDlg->m_TotalWaitTime = 0;
				m_pDispInfoDlg->m_TotalWarningTime = 0;
				m_pDispInfoDlg->m_CountTimes = 0;
				m_iTotalPositingFail = 0;

				TotalWorkTime = m_pDispInfoDlg->m_TotalWorkTime;
				TotalWaitTime = m_pDispInfoDlg->m_TotalWaitTime;
				TotalWarningTime = m_pDispInfoDlg->m_TotalWarningTime;
				TotalPositingFail = m_iTotalPositingFail;

				m_pDispInfoDlg->m_startTime = std::chrono::steady_clock::now();

				m_pDispInfoDlg->m_TotalTime = 0;
				TotalTime = m_pDispInfoDlg->m_TotalTime;

				TotalFaultTime = 0;
				TotalWorkRate = 0;
				TotalWaitRate = 0;
				TotalFaultRate = 0;

				m_pDispInfoDlg->m_output = 0;
				TotalOutPut = m_pDispInfoDlg->m_output;
				GetmtfInstance()->WriteInIFileStr("count", "output", QString::number(TotalOutPut), m_ProjectiniPath);

				//每小时数据===============================================================================
				lastTotalWorkTime = 0;
				lastTotalWaitTime = 0;
				lastTotalWarningTime = 0;

				curWorkTime = 0;
				curWaitTime = 0;
				curWarningTime = 0;
				curFaultTime = 0;
				workRate = 0;
				waitRate = 0;
				faultRate = 0;

				lastTotalOutput = 0;
				curOutPut = 0;

				lastPositingFail = 0;

				//===============================================================================
				lastTotalWorkTime = TotalWorkTime;
				lastTotalWaitTime = TotalWaitTime;
				lastTotalWarningTime = TotalWarningTime;
				lastTotalOutput = TotalOutPut;
				lastPositingFail = TotalPositingFail;
				//===============================================================================

				WriteWorkRateCsvData(TotalTime,
					curWorkTime, curWaitTime, curWarningTime, curFaultTime, curOutPut,
					workRate, waitRate, faultRate,
					TotalWorkTime, TotalWaitTime, TotalWarningTime, TotalFaultTime, TotalOutPut,
					TotalWorkRate, TotalWaitRate, TotalFaultRate, curPositingFail, TotalPositingFail);
				m_pProjectDB->WriteWorkRateDB(ConnName,TotalTime,
					curWorkTime, curWaitTime, curWarningTime, curFaultTime, curOutPut,
					workRate, waitRate, faultRate,
					TotalWorkTime, TotalWaitTime, TotalWarningTime, TotalFaultTime, TotalOutPut,
					TotalWorkRate, TotalWaitRate, TotalFaultRate, curPositingFail, TotalPositingFail);
				emit m_pWorkRateDlg->postInitCbxShift(true);
				LOG_DEBUG(glogger, MultUtf82Mult2("当班第一次WorkRate写入完成！"));
			}

		label_1:	
			//if ((hour >= 1) && (minute >= 58))
			if (hour >=1)
			//if (hour >1)
			{
				bReset = false;
				if (curminute == 0 && cursecond <= 10)//每个整点
				{
					if ((curhour != QTime::fromString(m_CheckTime[0]).hour()) && (curhour != QTime::fromString(m_CheckTime[1]).hour()))
						ProcessCheckCurrentTimeData(ConnName);
					LOG_DEBUG(glogger, MultUtf82Mult2("整点WorkRate写入完成！"));
					std::this_thread::sleep_for(std::chrono::milliseconds(1000 * 3588));
					continue;
				}
			}
			//else if ((hour <1)||((hour == 1) && (minute < 58)))
			else if (hour <1)
			//else if (hour <= 1)
			{			
				if (((curminute == 0 && cursecond <= 2)) || (hour == 0 && minute == 0 && second <= 2))//每个整点及倒计时最后一次写入
				{
					if ((QTime::fromString(m_CheckTime[0]).minute()==0)&& (QTime::fromString(m_CheckTime[1]).minute() == 0))
					{
						if ((curhour != QTime::fromString(m_CheckTime[0]).hour()) && (curhour != QTime::fromString(m_CheckTime[1]).hour()))
						{
							ProcessCheckCurrentTimeData(ConnName);
							LOG_DEBUG(glogger, MultUtf82Mult2("倒计时1小时内整点WorkRate写入！"));
						}
					}
					else {
						ProcessCheckCurrentTimeData(ConnName);
						LOG_DEBUG(glogger, MultUtf82Mult2("倒计时1小时内整点WorkRate写入！"));
					}


					if (hour == 0 && minute == 0 && second <= 3) {
						bFinishLastWrite = true;
						LOG_DEBUG(glogger, MultUtf82Mult2("当班最后一次写入完成"));
						mSleep(5000); continue; }
				}
			}
			mSleep(2000);
		}
		m_pProjectDB->removeConnection(ConnName);
	};
	//gthpool->AddTask(fun);
}

void ProjectDlg::ProcessCheckCurrentTimeData(QString ConnName)
{
	//总数据===============================================================================
	TotalWorkTime = m_pDispInfoDlg->m_TotalWorkTime;
	TotalWaitTime = m_pDispInfoDlg->m_TotalWaitTime;
	TotalWarningTime = m_pDispInfoDlg->m_TotalWarningTime;
	TotalPositingFail = m_iTotalPositingFail;

	auto TimeNow = std::chrono::steady_clock::now();
	m_pDispInfoDlg->m_TotalTime = GetmtfInstance()->durationTime(TimeNow, m_pDispInfoDlg->m_startTime, TimeType::second);

	TotalTime = m_pDispInfoDlg->m_TotalTime;
	if (TotalWorkTime > TotalTime) TotalWorkTime = TotalTime;
	if (TotalWaitTime > TotalTime) TotalWaitTime = TotalTime;
	if (TotalWarningTime > TotalTime) TotalWarningTime = TotalTime;
	TotalFaultTime = TotalTime - TotalWorkTime - TotalWaitTime - TotalWarningTime;
	TotalWorkRate = TotalWorkTime / TotalTime;
	TotalWaitRate = TotalWaitTime / TotalTime;
	TotalFaultRate = 1 - TotalWorkRate - TotalWaitRate;

	TotalOutPut = m_pDispInfoDlg->m_output;

	//每小时数据===============================================================================
	curWorkTime = TotalWorkTime - lastTotalWorkTime;
	curWaitTime = TotalWaitTime - lastTotalWaitTime;
	curWarningTime = TotalWarningTime - lastTotalWarningTime;
	curFaultTime = 3600 - curWorkTime - curWaitTime - curWarningTime;
	if (curFaultTime < 0) curFaultTime = 0;
	workRate = curWorkTime / 3600.0;
	waitRate = curWaitTime / 3600.0;
	faultRate = 1 - workRate - waitRate;
	if (faultRate < 0) faultRate = 0;
	curOutPut = TotalOutPut - lastTotalOutput;
	curPositingFail = TotalPositingFail - lastPositingFail;
	//===============================================================================
	lastTotalWorkTime = TotalWorkTime;
	lastTotalWaitTime = TotalWaitTime;
	lastTotalWarningTime = TotalWarningTime;
	lastTotalOutput = TotalOutPut;
	lastPositingFail = TotalPositingFail;
	//===============================================================================

	WriteWorkRateCsvData(TotalTime,
		curWorkTime, curWaitTime, curWarningTime, curFaultTime, curOutPut,
		workRate, waitRate, faultRate,
		TotalWorkTime, TotalWaitTime, TotalWarningTime, TotalFaultTime, TotalOutPut,
		TotalWorkRate, TotalWaitRate, TotalFaultRate, curPositingFail, TotalPositingFail);
	m_pProjectDB->WriteWorkRateDB(ConnName,TotalTime,
		curWorkTime, curWaitTime, curWarningTime, curFaultTime, curOutPut,
		workRate, waitRate, faultRate,
		TotalWorkTime, TotalWaitTime, TotalWarningTime, TotalFaultTime, TotalOutPut,
		TotalWorkRate, TotalWaitRate, TotalFaultRate, curPositingFail, TotalPositingFail);

	emit m_pWorkRateDlg->postInitCbxShift();
}

QString& ProjectDlg::GetSetTableName()
{
	lockup(m_TableNameMutex);
	return m_TableName;
}

std::vector<double> ProjectDlg::ReadRefPoint(QString filePath)
{
	std::vector<double> points;
	filePath.replace(".hobj", ".text");
	QFile file(filePath);
	if (!file.open(QIODevice::ReadWrite))
	{
		MessageBoxTip("参考点保存失败！");
		return std::vector<double>();
	}
	QByteArray strByte = file.readAll();
	QString strAll;
	strAll = QString::fromLocal8Bit(strByte);
	QStringList	strList = strAll.split("\n", Qt::SkipEmptyParts);
	for (int i = 0; i < strList.size(); i++)
	{
		auto strList2 = strList.at(i).split("：", Qt::SkipEmptyParts);
		QString strData = strList2.at(1);
		points.push_back(strData.toDouble());
	}
	file.close();
	return points;
}

void ProjectDlg::connection()
{
	connect(ui->btn_send_plc, &QPushButton::clicked, this, &ProjectDlg::OnPushButton);
	connect(ui->btn_FreshCmd_plc, &QPushButton::clicked, this, &ProjectDlg::OnPushButton);
	connect(ui->btn_load_cmd, &QPushButton::clicked, this, &ProjectDlg::OnPushButton);
	connect(ui->btn_openfolder_cmd, &QPushButton::clicked, this, &ProjectDlg::OnPushButton);
	connect(this, &ProjectDlg::postShowData, m_pDispInfoDlg, &DispInfoDlg::OnShowData);
	connect(ui->btn_func_test, &QPushButton::clicked, this, &ProjectDlg::OnFuncTest);
	//ui->btn_func_test->hide();
	//connect(ui->comboBox_RingType, static_cast<void(QComboBox::*)(const QString&)>(&QComboBox::currentTextChanged), this, &ProjectDlg::OnRingTypeChanged);
}

void ProjectDlg::connectLambda()
{
	connect(ui->radio_simulate, &QRadioButton::clicked, this, [&] {
		m_bSimulate = ui->radio_simulate->isChecked();
		});

	connect(ui->radio_simulateSavePic, &QRadioButton::clicked, this, [&] {
		m_bSimulateSavePic = ui->radio_simulateSavePic->isChecked();
		});

	connect(ui->radio_adjustNozzleModel, &QRadioButton::clicked, this, [&] {
		m_bAdjustNozzleModel = ui->radio_adjustNozzleModel->isChecked();
		m_pSktLinkMaster->WriteLongRegister("D1500", QString::number((int)m_bAdjustNozzleModel));
		//m_pSktLinkMaster->WriteLongRegister("D1500", QString::number(-12345));
		});

	connect(ui->radio_emptyRunWithSimImg, &QRadioButton::clicked, this, [&] {
		m_bEmpyRunWithSimImg = ui->radio_emptyRunWithSimImg->isChecked();
		ui->radio_ShieldError->setChecked(false);
		m_bShieldError = false;
		});

	connect(ui->radio_ShieldError, &QRadioButton::clicked, this, [&] {
		m_bShieldError = ui->radio_ShieldError->isChecked();
		});

	connect(ui->checkBox_timeOut, &QCheckBox::clicked, this, [=]()
		{
			m_pSktLinkMaster->m_bCheckTimeOut = ui->checkBox_timeOut->isChecked();
		});

	connect(ui->checkBox_heartBeat, &QCheckBox::clicked, this, [=]()
		{
			//m_pSktLinkMaster->m_bCheckHeartBeat = ui->checkBox_heartBeat->isChecked();
		});
	connect(ui->radio_SaveOkPic, &QCheckBox::clicked, this, [=]()
		{
			m_bSaveOkPic = ui->radio_SaveOkPic->isChecked();
		});
	connect(ui->radio_SaveNGPic, &QCheckBox::clicked, this, [=]()
		{
			m_bSaveNGPic = ui->radio_SaveNGPic->isChecked();
		});
	connect(ui->radio_ShieldComm, &QCheckBox::clicked, this, [=]()
		{
			m_bShieldComm = ui->radio_ShieldComm->isChecked();
		});
	connect(ui->radio_ShieldAppearance, &QCheckBox::clicked, this, [=]()
		{
			m_bShieldAppearance = ui->radio_ShieldAppearance->isChecked();

		if(m_bShieldAppearance)	GetmtfInstance()->WriteInIFileStr("setting", "m_bShieldAppearance","true", m_ProjectiniPath);
		else GetmtfInstance()->WriteInIFileStr("setting", "m_bShieldAppearance", "false", m_ProjectiniPath);

		});
	connect(ui->radio_shieldDeformation, &QCheckBox::clicked, this, [=]()
		{
			m_bShieldDeformation = ui->radio_shieldDeformation->isChecked();

			if (m_bShieldDeformation)	GetmtfInstance()->WriteInIFileStr("setting", "m_bShieldDeformation", "true", m_ProjectiniPath);
			else GetmtfInstance()->WriteInIFileStr("setting", "m_bShieldDeformation", "false", m_ProjectiniPath);
		});

	connect(ui->radio_shieldHight, &QCheckBox::clicked, this, [=]()
		{
			m_bShieldHight = ui->radio_shieldHight->isChecked();

			if (m_bShieldHight)	GetmtfInstance()->WriteInIFileStr("setting", "m_bShieldHight", "true", m_ProjectiniPath);
			else GetmtfInstance()->WriteInIFileStr("setting", "m_bShieldHight", "false", m_ProjectiniPath);
		});

	//ui->radio_ShieldAppearance->hide();
	connect(ui->radio_shieldWarPage, &QCheckBox::clicked, this, [=]()
		{
			m_bShieldWarPage = ui->radio_shieldWarPage->isChecked();
			if (m_bShieldWarPage)	GetmtfInstance()->WriteInIFileStr("setting", "m_bShieldWarPage", "true", m_ProjectiniPath);
			else GetmtfInstance()->WriteInIFileStr("setting", "m_bShieldWarPage", "false", m_ProjectiniPath);

		});


	connect(ui->radio_lockOffset, &QCheckBox::clicked, this, [=]()
		{
			m_bLockOffset = ui->radio_lockOffset->isChecked();
			UpdataTable_StandOffsetLoadRobot();
		});

	connect(ui->radio_Repeat_Test, &QCheckBox::clicked, this, [=]()
		{
			m_RepeatTest = ui->radio_Repeat_Test->isChecked();
		});
	connect(ui->radio_SaveOriginalPicture, &QCheckBox::clicked, this, [=]()
		{
			m_bSaveOriginalPicture = ui->radio_SaveOriginalPicture->isChecked();
		});
	connect(ui->radio_TriggerTest, &QCheckBox::clicked, this, [=]()
		{
			m_bTriggerTest = ui->radio_TriggerTest->isChecked();	
			m_bWorkingAuto = ui->radio_TriggerTest->isChecked();

		});
	connect(ui->radio_OldEquipment, &QCheckBox::clicked, this, [=]()
		{
			m_bOldEquipment= ui->radio_OldEquipment->isChecked();
			if (m_bOldEquipment)
			{
				m_pMesData->m_bConnectMes = false;
				g_pMesDlg->ui->checkBox_connectMes->setChecked(m_pMesData->m_bConnectMes);
			}
		});

	connect(ui->btn_Trigger1, &QPushButton::clicked, this, [=]()
		{
			SoftTrggerCam(CAM_NAME_0,0,0,true, TriggerCallBackFunCamera1,this);
		});
	connect(ui->btn_Trigger2, &QPushButton::clicked, this, [=]()
		{
			SoftTrggerCam(CAM_NAME_1, 1, 0, true, TriggerCallBackFunCamera2, this);
		});
	connect(ui->btn_Trigger3, &QPushButton::clicked, this, [=]()
		{
			SoftTrggerCam(CAM_NAME_2, 2, 0, true, TriggerCallBackFunCamera3, this);
		});
	connect(ui->btn_Trigger4, &QPushButton::clicked, this, [=]()
		{
			SoftTrggerCam(CAM_NAME_3, 3, 0, true, TriggerCallBackFunCamera4, this);
		});

	connect(ui->btn_save_ng_pic, &QPushButton::clicked, this, [=]()
		{
			QDateTime DateTime = QDateTime::currentDateTime();
			QString strProcessDate = DateTime.date().toString("yyyy-MM-dd");
			QString strTimeId = DateTime.toString("hhmmss");
			QString strTimeDot = DateTime.time().toString("hh:mm:ss");

			QString picName = "外观NG_" + strTimeId;

			if ((!m_bSimulate || m_bSimulateSavePic) && m_bSaveOkPic)
			{
				auto SaveImagefun = [=] {
					QString folderPath = m_PictureFolderPath + "/" + strProcessDate + "/临时外观NG图/"+m_ProductType;
					if (m_bSaveOriginalPicture)
					{
						Imgtfc::SaveImage(m_ImgFront, picName, folderPath);
					}
					else
					{
						Imgtfc::SaveImageCompression(m_ImgFront, picName, folderPath);
					}
				};
				gthpool->AddTask(SaveImagefun);
			}
		});
}

void ProjectDlg::OnFuncTest()
{
	auto res = m_pSktLinkMaster->ReadMR(EqStatus, 1);
	int num=res.at(0).toInt();

}

void ProjectDlg::ConnectCmd()
{	
	connect(m_pSktLinkMaster, &SocketLinkMaster::PostRecvWarning, m_pThis, &ProjectDlg::OnRecvRecvWarning);
	connect(m_pSktLinkMaster, &SocketLinkMaster::PostRecvEquipmentState, m_pThis, &ProjectDlg::OnRecvEquipmentState);
	connect(m_pSktLinkMaster, &SocketLinkMaster::PostRecvChangeProduct, m_pThis, &ProjectDlg::OnRecvChangeProduct);
	
}

//表格========================================================================
void ProjectDlg::ReadCmdPlc()
{
	QStringList strSplit;
	m_vecPlcCmdSet.clear();
	GetmtfInstance()->ReadPlcCmdSetFile(m_PlcCmdPath, m_vecPlcCmdSet);
	ui->cbx_cmd_plc->clear();
	for (int i = 0; i < m_vecPlcCmdSet.size(); ++i)
	{
		ui->cbx_cmd_plc->insertItem(i, QString::number(m_vecPlcCmdSet.at(i).at(0).toInt()));
	}
}

void ProjectDlg::InitWindFromConstructor()
{
	QString TableName = "StandOffsetRobot";
	m_TableObjMap[TableName]= ui->table_StandOffset;
	m_TableObjMap[TableName]->SetTableHeader("吸嘴号", "吸头X", "吸头Y", "吸头R", "相机X", "相机Y", "相机R", "offsetX", "offsetY","备注");
	m_TableObjMap[TableName]->SetTableRowCount(m_StandOffsetLoadRobot.size());
	m_TableObjMap[TableName]->InitOrderAtColumn(0);
	m_TableObjMap[TableName]->m_TableName = TableName;
	//m_TableObjMap[TableName]->setFocusPolicy(Qt::ClickFocus);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellDoubleClicked, this, &ProjectDlg::OnCellDoubleClicked);
	UpdataTable_StandOffsetLoadRobot(m_TableObjMap[TableName]->m_TableName);

	TableName = "StandPosImg";
	m_TableObjMap[TableName] = ui->table_StdImgPos;
	m_TableObjMap[TableName]->SetTableHeader("放料顺序", "图像坐标X", "图像坐标Y", "角度R", "备注");
	m_TableObjMap[TableName]->SetTableRowCount(m_StandImagePos.size());
	m_TableObjMap[TableName]->InitOrderAtColumn(0);
	m_TableObjMap[TableName]->SetTableCellSize(40, 40, 30, 80);
	m_TableObjMap[TableName]->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
	m_TableObjMap[TableName]->m_TableName = "StandPosImg";
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellDoubleClicked, this, &ProjectDlg::OnCellDoubleClicked);
	UpdataTable_StandImgPos(m_TableObjMap[TableName]->m_TableName);

	              
	TableName = "RotateCenterImg";
	m_TableObjMap[TableName] = ui->table_RotateCenter;
	m_TableObjMap[TableName]->SetTableHeader("吸嘴号", "图像坐标X", "图像坐标Y", "备注");
	m_TableObjMap[TableName]->SetTableRowCount(m_RotateCenterImg.size());
	m_TableObjMap[TableName]->InitOrderAtColumn(0);
	m_TableObjMap[TableName]->m_TableName = "RotateCenterImg";
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellDoubleClicked, this, &ProjectDlg::OnCellDoubleClicked);
	UpdataTable_RotateCenter(m_TableObjMap[TableName]->m_TableName);

	TableName = "ManualBC";
	m_TableObjMap[TableName] = ui->table_Manual;
	m_TableObjMap[TableName]->SetTableHeader("序号", "H补偿", "W补偿", "R补偿", "备注");
	m_TableObjMap[TableName]->SetTableRowCount(m_ManualBC.size());
	m_TableObjMap[TableName]->InitOrderAtColumn(0);


	m_TableObjMap[TableName]->SetTableCellSize(40, 50, 120, 120, 100);
	m_TableObjMap[TableName]->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
	m_TableObjMap[TableName]->m_TableName = "ManualBC";
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellDoubleClicked, this, &ProjectDlg::OnCellDoubleClicked);
	UpdataTable_ManualBC(m_TableObjMap[TableName]->m_TableName);

	TableName = "light";
	m_TableObjMap[TableName] = ui->table_light;
	m_TableObjMap[TableName]->SetTableHeader("位置ID", "亮度", "备注");
	m_TableObjMap[TableName]->SetTableRowCount(m_LightIntensity.size());
	m_TableObjMap[TableName]->InitOrderAtColumn(0);
	m_TableObjMap[TableName]->m_TableName = "light";
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellDoubleClicked, this, &ProjectDlg::OnCellDoubleClicked);
	UpdataTable_light(m_TableObjMap[TableName]->m_TableName);

	TableName = "AppearencePara";
	m_TableObjMap[TableName] = ui->table_AppearencePara;
	m_TableObjMap[TableName]->SetTableHeader("类别", "Gray", "Len", "Width", "Area", "备注");
	m_TableObjMap[TableName]->SetTableRowCount(m_AppearencePara.size());
	m_TableObjMap[TableName]->InitOrderAtColumn(0);
	//m_TableObjMap[TableName]->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
	//m_TableObjMap[TableName]->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
	//m_TableObjMap[TableName]->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
	//m_TableObjMap[TableName]->SetTableCellSize(40, 60, 80,80, 80, 80, 80);
	m_TableObjMap[TableName]->m_TableName = "AppearencePara";
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellDoubleClicked, this, &ProjectDlg::OnCellDoubleClicked);
	UpdataTable_AppearencePara(m_TableObjMap[TableName]->m_TableName);


	TableName = "ControlPara";
	m_TableObjMap[TableName] = ui->table_ControlPara;
	m_TableObjMap[TableName]->SetTableHeader("位置ID", "值", "备注");
	m_TableObjMap[TableName]->SetTableRowCount(m_ControlPara.size());
	m_TableObjMap[TableName]->InitOrderAtColumn(0);
	m_TableObjMap[TableName]->m_TableName = "ControlPara";
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellDoubleClicked, this, &ProjectDlg::OnCellDoubleClicked);
	UpdataTable_ControlPara(m_TableObjMap[TableName]->m_TableName);

	TableName = "CameraPara";
	m_TableObjMap[TableName] = ui->table_camera;
	m_TableObjMap[TableName]->SetTableHeader("相机ID", "曝光", "增益", "伽马", "备注");
	m_TableObjMap[TableName]->SetTableRowCount(m_CameraPara.size());
	m_TableObjMap[TableName]->InitOrderAtColumn(0);
	m_TableObjMap[TableName]->horizontalHeader()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
	m_TableObjMap[TableName]->SetTableCellSize(40, 60, 60, 80, 80, 60);
	m_TableObjMap[TableName]->m_TableName = "CameraPara";
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellDoubleClicked, this, &ProjectDlg::OnCellDoubleClicked);
	UpdataTable_CameraPara(m_TableObjMap[TableName]->m_TableName);

	TableName = "UpDwCamCalibPara";
	m_TableObjMap[TableName] = ui->table_UpDwCamCalibPara;
	m_TableObjMap[TableName]->m_TableName = "UpDwCamCalibPara";
	m_TableObjMap[TableName]->SetTableHeader("序号", "参数名", "坐标X", "坐标Y", "坐标R", "备注");
	m_TableObjMap[TableName]->SetTableRowCount(19);
	m_TableObjMap[TableName]->InitOrderAtColumn(0);
	m_TableObjMap[TableName]->AddItemCol("参数名", "上相机中心图像坐标");
	m_TableObjMap[TableName]->AddItemCol("参数名", "下相机中心图像坐标");
	m_TableObjMap[TableName]->AddItemCol("参数名", "上相机Mark图像坐标");
	m_TableObjMap[TableName]->AddItemCol("参数名", "上相机拍Mark机械坐标");
	m_TableObjMap[TableName]->AddItemCol("参数名", "下相机Mark图像坐标");
	m_TableObjMap[TableName]->AddItemCol("参数名", "拍照位1机械坐标");
	m_TableObjMap[TableName]->AddItemCol("参数名", "拍照位2机械坐标");
	m_TableObjMap[TableName]->AddItemCol("参数名", "1号吸头Mark图像坐标");
	m_TableObjMap[TableName]->AddItemCol("参数名", "2号吸头Mark图像坐标");
	m_TableObjMap[TableName]->AddItemCol("参数名", "3号吸头Mark图像坐标");
	m_TableObjMap[TableName]->AddItemCol("参数名", "4号吸头Mark图像坐标");
	m_TableObjMap[TableName]->AddItemCol("参数名", "5号吸头Mark图像坐标");
	m_TableObjMap[TableName]->AddItemCol("参数名", "6号吸头Mark图像坐标");

	m_TableObjMap[TableName]->AddItemCol("参数名", "上相机到1号吸头距离");
	m_TableObjMap[TableName]->AddItemCol("参数名", "上相机到2号吸头距离");
	m_TableObjMap[TableName]->AddItemCol("参数名", "上相机到3号吸头距离");
	m_TableObjMap[TableName]->AddItemCol("参数名", "上相机到4号吸头距离");
	m_TableObjMap[TableName]->AddItemCol("参数名", "上相机到5号吸头距离");
	m_TableObjMap[TableName]->AddItemCol("参数名", "上相机到6号吸头距离");
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellDoubleClicked, this, &ProjectDlg::OnCellDoubleClicked);
	UpdataTable_UpDwCamCalibPara(m_TableObjMap[TableName]->m_TableName);

	TableName = "CamNozzleDisBC";
	m_TableObjMap[TableName] = ui->table_CamNozzleDisBC;
	m_TableObjMap[TableName]->m_TableName = "CamNozzleDisBC";
	m_TableObjMap[TableName]->SetTableHeader("序号", "参数名", "坐标X", "坐标Y", "坐标R", "备注");
	m_TableObjMap[TableName]->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
	m_TableObjMap[TableName]->SetTableRowCount(6);
	m_TableObjMap[TableName]->InitOrderAtColumn(0);
	for (int i=1;i<=6;i++)
	{
		m_TableObjMap[TableName]->AddItemCol("参数名", "上相机到"+QString::number(i) + "号吸头距离补偿");
	}
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellDoubleClicked, this, &ProjectDlg::OnCellDoubleClicked);
	UpdataTable_CamNozzleDisBC(m_TableObjMap[TableName]->m_TableName);


	TableName = "ManualBC_Shape";
	m_TableObjMap[TableName] = ui->table_ManualBC_Shape;
	m_TableObjMap[TableName]->m_TableName = "ManualBC_Shape";
	m_TableObjMap[TableName]->SetTableHeader("序号", "Width1", "Width2", "Width3", "Width4", "R1", "R2", "R3", "R4", "备注");
	m_TableObjMap[TableName]->horizontalHeader()->setSectionResizeMode(1, QHeaderView::ResizeToContents);
	m_TableObjMap[TableName]->SetTableRowCount(1);
	m_TableObjMap[TableName]->InitOrderAtColumn(0);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellDoubleClicked, this, &ProjectDlg::OnCellDoubleClicked);
	UpdataTable_ManualBC_Shape(m_TableObjMap[TableName]->m_TableName);


	TableName = "NozzleHight";
	m_TableObjMap[TableName] = ui->table_NozzleHight;
	m_TableObjMap[TableName]->SetTableHeader("位置ID", "高度", "备注");
	m_TableObjMap[TableName]->SetTableRowCount(m_NozzleHight.size());
	m_TableObjMap[TableName]->InitOrderAtColumn(0);
	m_TableObjMap[TableName]->m_TableName = TableName;
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	connect(m_TableObjMap[TableName], &MyTableWidget::cellDoubleClicked, this, &ProjectDlg::OnCellDoubleClicked);
	UpdataTable_NozzleHight(m_TableObjMap[TableName]->m_TableName);

//========================================================================================================
	ui->checkBox_timeOut->setChecked(Pgv::getbCheckTimeOut());
	ui->checkBox_heartBeat->setChecked(Pgv::getbCheckHeartBeat());

	ui->radio_SaveOkPic->setChecked(m_bSaveOkPic);
	ui->radio_SaveNGPic->setChecked(m_bSaveNGPic);

	m_pTabPara->removeTabEx("tab_CamNozzleDisBC");
	m_pTabPara->removeTabEx("tab_UpDwCamCalibPara");

	m_pTabPara->removeTabEx("tab_StandOffset");
	m_pTabPara->removeTabEx("tab_RotateCenter");
	m_pTabPara->removeTabEx("tab_LimitData");
	m_pTabPara->removeTabEx("tab_StdImgPos");
}

void ProjectDlg::InitTableFromDB()
{
	UpdataTable_StandOffsetLoadRobot();
	UpdataTable_StandImgPos();
	UpdataTable_RotateCenter();
	UpdataTable_ManualBC();
	UpdataTable_light();
	UpdataTable_AppearencePara();
	UpdataTable_ControlPara();
	UpdataTable_CameraPara();
	UpdataTable_UpDwCamCalibPara();
	UpdataTable_CamNozzleDisBC();
	//UpdataTable_SlotImgPos();
	UpdataTable_ManualBC_Shape();
	UpdataTable_NozzleHight();
}

void ProjectDlg::OnCellDoubleClicked(int row, int column)
{
	MyTableWidget* pTable = (MyTableWidget*)sender();
    m_ClickedValue = pTable->GetText(row, column);
}

void ProjectDlg::OnEditTable(int row, int column)
{
	MyTableWidget* pTable = (MyTableWidget*)sender();
	auto res = QMessageBox::StandardButton::NoButton;
	res = QMessageBox::information(0, "提示", "是否更改此参数?", QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::No);
	if (res == QMessageBox::StandardButton::No)
	{
		disconnect(pTable, &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
		pTable->setItemEx(column, row, m_ClickedValue);
		connect(pTable, &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
		return;
	}
	QString value,name;
	value = pTable->GetText(row, column);
	name = pTable->GetText(row, 1);
	if (pTable->m_TableName == "StandOffsetRobot")
	{
		if (column == 1)
		{
			m_NozzlePosRobot.at(row).x = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "取料位标定参数", "吸头X", value, "rowid", QString::number(row + 1));
		}
		else if (column == 2)
		{
			m_NozzlePosRobot.at(row).y = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "取料位标定参数", "吸头Y", value, "rowid", QString::number(row + 1));
		}
		else if (column == 3) {
			m_NozzlePosRobot.at(row).R = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "取料位标定参数", "吸头R", value, "rowid", QString::number(row + 1));
		}

		else if (column == 4)
		{
			m_CameraPosRobot.at(row).x = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "取料位标定参数", "相机X", value, "rowid", QString::number(row + 1));
		}
		else if (column == 5) {
			m_CameraPosRobot.at(row).y = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "取料位标定参数", "相机Y", value, "rowid", QString::number(row + 1));
		}
		else if (column == 6) {
			m_CameraPosRobot.at(row).R = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "取料位标定参数", "相机R", value, "rowid", QString::number(row + 1));
		}

		if (!m_bLockOffset)
		{
			m_StandOffsetLoadRobot.at(row).x = m_NozzlePosRobot.at(row).x - m_CameraPosRobot.at(row).x;
			m_StandOffsetLoadRobot.at(row).y = m_NozzlePosRobot.at(row).y - m_CameraPosRobot.at(row).y;
			GetmtfInstance()->UpdateSingleValue("conn1", "取料位标定参数", "OffsetX", QString::number(m_StandOffsetLoadRobot.at(row).x), "rowid", QString::number(row + 1));
			GetmtfInstance()->UpdateSingleValue("conn1", "取料位标定参数", "OffsetY", QString::number(m_StandOffsetLoadRobot.at(row).y), "rowid", QString::number(row + 1));
		}

		UpdataTable_StandOffsetLoadRobot();
	}
	else if (pTable->m_TableName == "StandPosImg")
	{
		if (column == 1)
		{
			m_StandImagePos.at(row).x = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "放料标准图像位置", "图像坐标X", value, "rowid", QString::number(row + 1));
		}
		else if (column == 2)
		{
			m_StandImagePos.at(row).y = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "放料标准图像位置", "图像坐标Y", value, "rowid", QString::number(row + 1));
		}
		else if (column == 3)
		{
			m_StandImagePos.at(row).R = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "放料标准图像位置", "角度R", value, "rowid", QString::number(row + 1));
		}
	}
	else if (pTable->m_TableName == "RotateCenterImg")
	{
		if (column == 1) {
			m_RotateCenterImg.at(row).x = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1","旋转中心","X坐标", value,"rowid",QString::number(row+1));
		}
		else if (column == 2) {
			m_RotateCenterImg.at(row).y = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "旋转中心", "Y坐标", value, "rowid", QString::number(row+1));
		}
	}
	else if (pTable->m_TableName == "ManualBC")
	{
		if (column == 1)
		{
			m_ManualBC.at(row).x = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "补偿", "H补偿", value, "rowid", QString::number(row + 1));
		}
		else if (column == 2)
		{
			m_ManualBC.at(row).y = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "补偿", "W补偿", value, "rowid", QString::number(row + 1));
		}
		else if (column == 3) {
			m_ManualBC.at(row).R = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "补偿", "R补偿", value, "rowid", QString::number(row + 1));
		}
	}
	else if (pTable->m_TableName == "light")
	{
		if (column == 1)
		{
			m_LightIntensity.at(row).P0 = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "光源参数", "亮度", value, "rowid", QString::number(row + 1));
		}
	}
	else if (pTable->m_TableName == "NozzleHight")
	{
		if (column == 1)
		{
			m_NozzleHight.at(row).P0 = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "吸嘴高度", "高度", value, "rowid", QString::number(row + 1));
		}
	}
	else if (pTable->m_TableName == "AppearencePara")
	{
		if (column == 1) {
			m_AppearencePara.at(row).Gray = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "外观检测参数", "Gray", value, "rowid", QString::number(row + 1));
			m_Gray[row]= value.toDouble();
		}
		else if (column == 2) {
			m_AppearencePara.at(row).Len = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "外观检测参数", "Len", value, "rowid", QString::number(row + 1));
			m_Len[row] = value.toDouble();
		}
		else if (column == 3) {
			m_AppearencePara.at(row).Width = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "外观检测参数", "Width", value, "rowid", QString::number(row + 1));
			m_Width[row] = value.toDouble();
		}
		else if (column == 4) {
			m_AppearencePara.at(row).Area = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "外观检测参数", "Area", value, "rowid", QString::number(row + 1));
			m_Area[row] = value.toDouble();
		}
	}
	else if (pTable->m_TableName == "ControlPara")
	{
		if (column == 1) {
			m_ControlPara.at(row).P0= value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "图像控制参数", "值", value, "rowid", QString::number(row + 1));
		}
	}
	else if (pTable->m_TableName == "CameraPara")
	{
		if (column == 1) {
			m_CameraPara.at(row).P0= value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "相机参数", "曝光", value, "rowid", QString::number(row + 1));
		}
		else if (column == 2) {
			m_CameraPara.at(row).P1 = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "相机参数", "增益", value, "rowid", QString::number(row + 1));
		}
		else if (column == 3) {
			m_CameraPara.at(row).P2 = value.toDouble();
			GetmtfInstance()->UpdateSingleValue("conn1", "相机参数", "伽马", value, "rowid", QString::number(row + 1));
		}
		InitCameraPara();
	}
	else if (pTable->m_TableName == "UpDwCamCalibPara")
	{
		if (row == 0)//上相机中心图像坐标
		{
			if (column == 2) {
				m_UpCameraCenter.x = value.toDouble();
				GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标X", value, "参数名", "上相机中心图像坐标", "1,1");
			}
			if (column == 3) {
				m_UpCameraCenter.y = value.toDouble();
				GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标Y", value, "参数名", "上相机中心图像坐标", "1,1");
			}
			if (column == 4) {
				m_UpCameraCenter.R = value.toDouble();
				GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标R", value, "参数名", "上相机中心图像坐标", "1,1");
			}
		}
		else if (row == 1)//下相机中心图像坐标
		{
			if (column == 2) {
				m_DwCameraCenter.x = value.toDouble();
				GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标X", value, "参数名", "下相机中心图像坐标", "1,1");
			}
			if (column == 3) {
				m_DwCameraCenter.y = value.toDouble();
				GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标Y", value, "参数名", "下相机中心图像坐标", "1,1");
			}
			if (column == 4) {
				m_DwCameraCenter.R = value.toDouble();
				GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标R", value, "参数名", "下相机中心图像坐标", "1,1");
			}
		}
		else if (row == 2)//上相机Mark图像坐标
		{
			if (column == 2) {
				m_UpCameraPotoMarkPos.x = value.toDouble();
				GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标X", value, "参数名", "上相机Mark图像坐标", "1,1"); 
			}
			if (column == 3){
				m_UpCameraPotoMarkPos.y = value.toDouble();
				GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标Y", value, "参数名", "上相机Mark图像坐标", "1,1");
			}
			if (column == 4) {
				m_UpCameraPotoMarkPos.R = value.toDouble();
				GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标R", value, "参数名", "上相机Mark图像坐标", "1,1");
			}
		}
		else if (row == 3)//上相机拍Mark机械坐标
		{
			if (column == 2)	m_UpCameraPotoMarkPosRobot.x = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标X", value, "参数名", "上相机拍Mark机械坐标", "1,1");
			if (column == 3)	m_UpCameraPotoMarkPosRobot.y = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标Y", value, "参数名", "上相机拍Mark机械坐标", "1,1");
			if (column == 4)	m_UpCameraPotoMarkPosRobot.R = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标R", value, "参数名", "上相机拍Mark机械坐标", "1,1");
		}
		else if (row == 4)//下相机Mark图像坐标
		{
			if (column == 2)	m_DwCameraPotoMarkPos.x = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标X", value, "参数名", "下相机Mark图像坐标", "1,1");
			if (column == 3)	m_DwCameraPotoMarkPos.y = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标Y", value, "参数名", "下相机Mark图像坐标", "1,1");
			if (column == 4)	m_DwCameraPotoMarkPos.R = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标R", value, "参数名", "下相机Mark图像坐标", "1,1");
		}
		else if (row == 5)//拍照位1机械坐标
		{
			if (column == 2)	m_PotoPosWs1.x = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标X", value, "参数名", "拍照位1机械坐标", "1,1");
			if (column == 3)	m_PotoPosWs1.y = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标Y", value, "参数名", "拍照位1机械坐标", "1,1");
			if (column == 4)	m_PotoPosWs1.R = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标R", value, "参数名", "拍照位1机械坐标", "1,1");
		}
		else if (row == 6)//拍照位2机械坐标
		{
			if (column == 2)	m_PotoPosWs2.x = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标X", value, "参数名", "拍照位2机械坐标", "1,1");
			if (column == 3)	m_PotoPosWs2.y = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标Y", value, "参数名", "拍照位2机械坐标", "1,1");
			if (column == 4)	m_PotoPosWs2.R = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标R", value, "参数名", "拍照位2机械坐标", "1,1");
		}
		else if (row == 7)//1号吸头Mark图像坐标
		{
			int m = 0;
			if (column == 2)	m_NozzleMarkPos.at(m).x = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标X", value, "参数名", "1号吸头Mark图像坐标", "1,1");
			if (column == 3)	m_NozzleMarkPos.at(m).y = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标Y", value, "参数名", "1号吸头Mark图像坐标", "1,1");
			if (column == 4)	m_NozzleMarkPos.at(m).R = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标R", value, "参数名", "1号吸头Mark图像坐标", "1,1");
		}
		else if (row == 8)//2号吸头Mark图像坐标
		{
			int m = 1;
			if (column == 2)	 m_NozzleMarkPos.at(m).x = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标X", value, "参数名", "2号吸头Mark图像坐标", "1,1");
			if (column == 3)	m_NozzleMarkPos.at(m).y = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标Y", value, "参数名", "2号吸头Mark图像坐标", "1,1");
			if (column == 4)	m_NozzleMarkPos.at(m).R = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标R", value, "参数名", "2号吸头Mark图像坐标", "1,1");
		}
		else if (row == 9)//3号吸头Mark图像坐标
		{
			int m = 2;
			if (column == 2)	 m_NozzleMarkPos.at(m).x = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标X", value, "参数名", "3号吸头Mark图像坐标", "1,1");
			if (column == 3)	m_NozzleMarkPos.at(m).y = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标Y", value, "参数名", "3号吸头Mark图像坐标", "1,1");
			if (column == 4)	m_NozzleMarkPos.at(m).R = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标R", value, "参数名", "3号吸头Mark图像坐标", "1,1");
		}
		else if (row == 10)//4号吸头Mark图像坐标
		{
			int m = 3;
			if (column == 2)	 m_NozzleMarkPos.at(m).x = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标X", value, "参数名", "4号吸头Mark图像坐标", "1,1");
			if (column == 3)	m_NozzleMarkPos.at(m).y = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标Y", value, "参数名", "4号吸头Mark图像坐标", "1,1");
			if (column == 4)	m_NozzleMarkPos.at(m).R = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标R", value, "参数名", "4号吸头Mark图像坐标", "1,1");
		}
		else if (row == 11)//5号吸头Mark图像坐标
		{
			int m = 4;
			if (column == 2)	 m_NozzleMarkPos.at(m).x = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标X", value, "参数名", "5号吸头Mark图像坐标", "1,1");
			if (column == 3)	m_NozzleMarkPos.at(m).y = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标Y", value, "参数名", "5号吸头Mark图像坐标", "1,1");
			if (column == 4)	m_NozzleMarkPos.at(m).R = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标R", value, "参数名", "5号吸头Mark图像坐标", "1,1");
		}
		else if (row == 12)//6号吸头Mark图像坐标
		{
			int m = 5;
			if (column == 2)	m_NozzleMarkPos.at(m).x = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标X", value, "参数名", "6号吸头Mark图像坐标", "1,1");
			if (column == 3)	m_NozzleMarkPos.at(m).y = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标Y", value, "参数名", "6号吸头Mark图像坐标", "1,1");
			if (column == 4)	m_NozzleMarkPos.at(m).R = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离参数表", "坐标R", value, "参数名", "6号吸头Mark图像坐标", "1,1");
		}
	}
	else if (pTable->m_TableName == "CamNozzleDisBC")
	{
		int m = row;
		if (column == 2)	m_UpCamera2NozzleOffsetBCWs.at(m).x = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离补偿表", "坐标X", value, "参数名", "上相机到" + QString::number(m+1) + "号吸头距离补偿", "1,1");
		if (column == 3)	m_UpCamera2NozzleOffsetBCWs.at(m).y = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离补偿表", "坐标Y", value, "参数名", "上相机到" + QString::number(m+1) + "号吸头距离补偿", "1,1");
		if (column == 4)	m_UpCamera2NozzleOffsetBCWs.at(m).R = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "相机吸嘴距离补偿表", "坐标R", value, "参数名", "上相机到" + QString::number(m+1) + "号吸头距离补偿", "1,1");
	}
	else if (pTable->m_TableName == "ManualBC_Shape")
	{
		int m = row;
		if (column == 1)	m_ShapeParaBC.at(m).P0 = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "变形补偿", "Width1", value, "rowid", QString::number(row + 1));
		if (column == 2)	m_ShapeParaBC.at(m).P1 = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "变形补偿", "Width2", value, "rowid", QString::number(row + 1));
		if (column == 3)	m_ShapeParaBC.at(m).P2 = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "变形补偿", "Width3", value, "rowid", QString::number(row + 1));
		if (column == 4)	m_ShapeParaBC.at(m).P3 = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "变形补偿", "Width4", value, "rowid", QString::number(row + 1));
		if (column == 5)	m_ShapeParaBC.at(m).P4 = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "变形补偿", "R1", value, "rowid", QString::number(row + 1));
		if (column == 6)	m_ShapeParaBC.at(m).P5 = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "变形补偿", "R2", value, "rowid", QString::number(row + 1));
		if (column == 7)	m_ShapeParaBC.at(m).P6 = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "变形补偿", "R3", value, "rowid", QString::number(row + 1));
		if (column == 8)	m_ShapeParaBC.at(m).P7 = value.toDouble(), GetmtfInstance()->UpdateSingleValue("conn1", "变形补偿", "R4", value, "rowid", QString::number(row + 1));

    }
}

void ProjectDlg::UpdataTable_SlotImgPos(QString TableName) {

	disconnect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	int row = 0;
	int m = 0;
	for (row = 0, m = 0; m < 24; m++, row++)
	{
		m_slotImgPos.at(m).x = GetmtfInstance()->QuerySingleValue2Double("conn1", "穴位图像坐标表", "坐标X", "参数名", QString::number(m+1) + "号放料穴位", true);
		m_slotImgPos.at(m).y = GetmtfInstance()->QuerySingleValue2Double("conn1", "穴位图像坐标表", "坐标Y", "参数名", QString::number(m+1) + "号放料穴位", true);
		m_slotImgPos.at(m).R = GetmtfInstance()->QuerySingleValue2Double("conn1", "穴位图像坐标表", "坐标R", "参数名", QString::number(m+1) + "号放料穴位", true);

		m_TableObjMap[TableName]->setItemEx("坐标X", row, QString::number(Round_off(m_slotImgPos.at(m).x, 2), 'f', 2));
		m_TableObjMap[TableName]->setItemEx("坐标Y", row, QString::number(Round_off(m_slotImgPos.at(m).y, 2), 'f', 2));
		m_TableObjMap[TableName]->setItemEx("坐标R", row, QString::number(Round_off(m_slotImgPos.at(m).R, 2), 'f', 2));

		if (m==0||m==6||m==12 || m == 1 || m == 7 || m == 13)
		{
			m_TableObjMap[TableName]->SetFlags("坐标X", row, 0);
			m_TableObjMap[TableName]->SetFlags("坐标Y", row, 0);
			m_TableObjMap[TableName]->SetFlags("坐标R", row, 0);
		}
	}
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
}

void ProjectDlg::UpdataTable_CamNozzleDisBC(QString TableName)
{
	disconnect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	int row = 0;
	int m = 0;
	for (row =0, m = 0; m < 6; m++, row++)
	{
		m_UpCamera2NozzleOffsetBCWs.at(m).x = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离补偿表", "坐标X", "参数名", "上相机到" + QString::number(m + 1) + "号吸头距离补偿", true);
		m_UpCamera2NozzleOffsetBCWs.at(m).y = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离补偿表", "坐标Y", "参数名", "上相机到" + QString::number(m + 1) + "号吸头距离补偿", true);
		m_UpCamera2NozzleOffsetBCWs.at(m).R = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离补偿表", "坐标R", "参数名", "上相机到" + QString::number(m + 1) + "号吸头距离补偿", true);

		m_TableObjMap[TableName]->setItemEx("坐标X", row, QString::number(Round_off(m_UpCamera2NozzleOffsetBCWs.at(m).x, 2), 'f', 2));
		m_TableObjMap[TableName]->setItemEx("坐标Y", row, QString::number(Round_off(m_UpCamera2NozzleOffsetBCWs.at(m).y, 2), 'f', 2));
		m_TableObjMap[TableName]->setItemEx("坐标R", row, QString::number(Round_off(m_UpCamera2NozzleOffsetBCWs.at(m).R, 2), 'f', 2));
	}
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
}

void ProjectDlg::UpdataTable_StandOffsetLoadRobot(QString TableName)
{
	disconnect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	int row = 0;

	for (row = 0; row < m_CameraPosRobot.size(); row++)
	{
		m_NozzlePosRobot.at(row).x= GetmtfInstance()->QuerySingleValue2Double("conn1", "取料位标定参数", "吸头X", "rowid", QString::number(row + 1));
		m_NozzlePosRobot.at(row).y = GetmtfInstance()->QuerySingleValue2Double("conn1", "取料位标定参数", "吸头Y", "rowid", QString::number(row + 1));
		m_NozzlePosRobot.at(row).R = GetmtfInstance()->QuerySingleValue2Double("conn1", "取料位标定参数", "吸头R", "rowid", QString::number(row + 1));
	
		m_CameraPosRobot.at(row).x = GetmtfInstance()->QuerySingleValue2Double("conn1", "取料位标定参数", "相机X", "rowid", QString::number(row + 1));
		m_CameraPosRobot.at(row).y = GetmtfInstance()->QuerySingleValue2Double("conn1", "取料位标定参数", "相机Y", "rowid", QString::number(row + 1));
		m_CameraPosRobot.at(row).R = GetmtfInstance()->QuerySingleValue2Double("conn1", "取料位标定参数", "相机R", "rowid", QString::number(row + 1));

		m_StandOffsetLoadRobot.at(row).x = GetmtfInstance()->QuerySingleValue2Double("conn1", "取料位标定参数", "OffsetX", "rowid", QString::number(row + 1));
		m_StandOffsetLoadRobot.at(row).y = GetmtfInstance()->QuerySingleValue2Double("conn1", "取料位标定参数", "OffsetY", "rowid", QString::number(row + 1));
		m_StandOffsetLoadRobot.at(row).R = GetmtfInstance()->QuerySingleValue2Double("conn1", "取料位标定参数", "OffsetR", "rowid", QString::number(row + 1));
	}

	for (row = 0; row < m_CameraPosRobot.size(); row++)
	{
		m_TableObjMap[TableName]->setItemEx("吸嘴号", row, QString::number(row + 1));
		m_TableObjMap[TableName]->setItemEx("吸头X", row, QString::number(m_NozzlePosRobot.at(row).x));
		m_TableObjMap[TableName]->setItemEx("吸头Y", row, QString::number(m_NozzlePosRobot.at(row).y));
		m_TableObjMap[TableName]->setItemEx("吸头R", row, QString::number(m_NozzlePosRobot.at(row).R));

		m_TableObjMap[TableName]->setItemEx("相机X", row, QString::number(m_CameraPosRobot.at(row).x));
		m_TableObjMap[TableName]->setItemEx("相机Y", row, QString::number(m_CameraPosRobot.at(row).y));
		m_TableObjMap[TableName]->setItemEx("相机R", row, QString::number(m_CameraPosRobot.at(row).R));

		m_TableObjMap[TableName]->setItemEx("offsetX", row, QString::number(m_StandOffsetLoadRobot.at(row).x));
		m_TableObjMap[TableName]->setItemEx("offsetY", row, QString::number(m_StandOffsetLoadRobot.at(row).y));

		m_TableObjMap[TableName]->SetFlags("offsetX", row, 0);
		m_TableObjMap[TableName]->SetFlags("offsetY", row, 0);

		if (row==0)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "以下取料偏移");
		}
		if (/*4<=row&& */m_bLockOffset)
		{
			m_CameraPosRobot.at(row).x = m_NozzlePosRobot.at(row).x - m_StandOffsetLoadRobot.at(row).x;
			m_CameraPosRobot.at(row).y = m_NozzlePosRobot.at(row).y - m_StandOffsetLoadRobot.at(row).y;
			//m_CameraPosRobot.at(row).angle = m_NozzlePosRobot.at(row).angle - m_StandOffsetLoadRobot.at(row).angle;
			GetmtfInstance()->UpdateSingleValue("conn1", "取料位标定参数", "相机X",QString::number(m_CameraPosRobot.at(row).x), "rowid", QString::number(row + 1));
			GetmtfInstance()->UpdateSingleValue("conn1", "取料位标定参数", "相机Y", QString::number(m_CameraPosRobot.at(row).y), "rowid", QString::number(row + 1));

			m_TableObjMap[TableName]->setItemEx("相机X", row, QString::number(m_CameraPosRobot.at(row).x));
			m_TableObjMap[TableName]->setItemEx("相机Y", row, QString::number(m_CameraPosRobot.at(row).y));
			m_TableObjMap[TableName]->setItemEx("相机R", row, QString::number(m_CameraPosRobot.at(row).R));

			m_TableObjMap[TableName]->setItemEx("offsetX", row, QString::number(m_StandOffsetLoadRobot.at(row).x));
			m_TableObjMap[TableName]->setItemEx("offsetY", row, QString::number(m_StandOffsetLoadRobot.at(row).y));

			m_TableObjMap[TableName]->SetFlags("相机X", row, 0);
			m_TableObjMap[TableName]->SetFlags("相机Y", row, 0);
			m_TableObjMap[TableName]->SetFlags("相机R", row, 0);

			m_TableObjMap[TableName]->SetFlags("offsetX", row, 0);
			m_TableObjMap[TableName]->SetFlags("offsetY", row, 0);
		}
	}
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
}

void ProjectDlg::UpdataTable_UpDwCamCalibPara(QString TableName)
{
	disconnect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	int row = 0;
	m_UpCameraCenter.x = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标X", "参数名", "上相机中心图像坐标", true);
	m_UpCameraCenter.y = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标Y", "参数名", "上相机中心图像坐标", true);
	m_UpCameraCenter.R = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标R", "参数名", "上相机中心图像坐标", true);

	m_TableObjMap[TableName]->setItemEx("坐标X", row, QString::number(Round_off(m_UpCameraCenter.x, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标Y", row, QString::number(Round_off(m_UpCameraCenter.y, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标R", row, QString::number(Round_off(m_UpCameraCenter.R, 2), 'f', 2));

	row = 1;
	m_DwCameraCenter.x = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标X", "参数名", "下相机中心图像坐标", true);
	m_DwCameraCenter.y = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标Y", "参数名", "下相机中心图像坐标", true);
	m_DwCameraCenter.R = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标R", "参数名", "下相机中心图像坐标", true);

	m_TableObjMap[TableName]->setItemEx("坐标X", row, QString::number(Round_off(m_DwCameraCenter.x, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标Y", row, QString::number(Round_off(m_DwCameraCenter.y, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标R", row, QString::number(Round_off(m_DwCameraCenter.R, 2), 'f', 2));

	row = 2;
	m_UpCameraPotoMarkPos.x=GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标X",  "参数名", "上相机Mark图像坐标",true);
	m_UpCameraPotoMarkPos.y = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标Y", "参数名", "上相机Mark图像坐标", true);
	m_UpCameraPotoMarkPos.R = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标R", "参数名", "上相机Mark图像坐标", true);

	m_TableObjMap[TableName]->setItemEx("坐标X", row, QString::number(Round_off(m_UpCameraPotoMarkPos.x, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标Y", row, QString::number(Round_off(m_UpCameraPotoMarkPos.y, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标R", row, QString::number(Round_off(m_UpCameraPotoMarkPos.R, 2), 'f', 2));
	row = 3;
	m_UpCameraPotoMarkPosRobot.x = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标X", "参数名", "上相机拍Mark机械坐标", true);
	m_UpCameraPotoMarkPosRobot.y = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标Y", "参数名", "上相机拍Mark机械坐标", true);
	m_UpCameraPotoMarkPosRobot.R = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标R", "参数名", "上相机拍Mark机械坐标", true);

	m_TableObjMap[TableName]->setItemEx("坐标X", row, QString::number(Round_off(m_UpCameraPotoMarkPosRobot.x, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标Y", row, QString::number(Round_off(m_UpCameraPotoMarkPosRobot.y, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标R", row, QString::number(Round_off(m_UpCameraPotoMarkPosRobot.R, 2), 'f', 2));
	row = 4;
	m_DwCameraPotoMarkPos.x = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标X", "参数名", "下相机Mark图像坐标", true);
	m_DwCameraPotoMarkPos.y = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标Y", "参数名", "下相机Mark图像坐标", true);
	m_DwCameraPotoMarkPos.R = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标R", "参数名", "下相机Mark图像坐标", true);

	m_TableObjMap[TableName]->setItemEx("坐标X", row, QString::number(Round_off(m_DwCameraPotoMarkPos.x, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标Y", row, QString::number(Round_off(m_DwCameraPotoMarkPos.y, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标R", row, QString::number(Round_off(m_DwCameraPotoMarkPos.R, 2), 'f', 2));

	row = 5;
	m_PotoPosWs1.x = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标X", "参数名", "拍照位1机械坐标", true);
	m_PotoPosWs1.y = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标Y", "参数名", "拍照位1机械坐标", true);
	m_PotoPosWs1.R = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标R", "参数名", "拍照位1机械坐标", true);

	m_TableObjMap[TableName]->setItemEx("坐标X", row, QString::number(Round_off(m_PotoPosWs1.x, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标Y", row, QString::number(Round_off(m_PotoPosWs1.y, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标R", row, QString::number(Round_off(m_PotoPosWs1.R, 2), 'f', 2));
	row = 6;
	m_PotoPosWs2.x = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标X", "参数名", "拍照位2机械坐标", true);
	m_PotoPosWs2.y = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标Y", "参数名", "拍照位2机械坐标", true);
	m_PotoPosWs2.R = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标R", "参数名", "拍照位2机械坐标", true);

	m_TableObjMap[TableName]->setItemEx("坐标X", row, QString::number(Round_off(m_PotoPosWs2.x, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标Y", row, QString::number(Round_off(m_PotoPosWs2.y, 2), 'f', 2));
	m_TableObjMap[TableName]->setItemEx("坐标R", row, QString::number(Round_off(m_PotoPosWs2.R, 2), 'f', 2));
	int m = 0;
	for (row = 7, m = 0; m < 6; m++, row++)
	{
		m_NozzleMarkPos.at(m).x = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标X", "参数名", QString::number(m + 1) + "号吸头Mark图像坐标", true);
		m_NozzleMarkPos.at(m).y = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标Y", "参数名", QString::number(m + 1) + "号吸头Mark图像坐标", true);
		m_NozzleMarkPos.at(m).R = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标R", "参数名", QString::number(m + 1) + "号吸头Mark图像坐标", true);

		m_TableObjMap[TableName]->setItemEx("坐标X", row, QString::number(Round_off(m_NozzleMarkPos.at(m).x, 2), 'f', 2));
		m_TableObjMap[TableName]->setItemEx("坐标Y", row, QString::number(Round_off(m_NozzleMarkPos.at(m).y, 2), 'f', 2));
		m_TableObjMap[TableName]->setItemEx("坐标R", row, QString::number(Round_off(m_NozzleMarkPos.at(m).R, 2), 'f', 2));
	}

	for (row = 13,m=0;m<6;m++,row++)
	{
		m_UpCamera2NozzleOffsetWs.at(m).x = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标X", "参数名", "上相机到"+QString::number(m + 1) + "号吸头距离", true);
		m_UpCamera2NozzleOffsetWs.at(m).y = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标Y", "参数名", "上相机到" + QString::number(m + 1) + "号吸头距离", true);
		m_UpCamera2NozzleOffsetWs.at(m).R = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机吸嘴距离参数表", "坐标R", "参数名", "上相机到" + QString::number(m + 1) + "号吸头距离", true);

		m_TableObjMap[TableName]->setItemEx("坐标X", row, QString::number(Round_off(m_UpCamera2NozzleOffsetWs.at(m).x, 2), 'f', 2));
		m_TableObjMap[TableName]->setItemEx("坐标Y", row, QString::number(Round_off(m_UpCamera2NozzleOffsetWs.at(m).y, 2), 'f', 2));
		m_TableObjMap[TableName]->setItemEx("坐标R", row, QString::number(Round_off(m_UpCamera2NozzleOffsetWs.at(m).R, 2), 'f', 2));
		m_TableObjMap[TableName]->SetFlags("坐标X", row, 0);
		m_TableObjMap[TableName]->SetFlags("坐标Y", row, 0);
		m_TableObjMap[TableName]->SetFlags("坐标R", row, 0);
	}

	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
}

void ProjectDlg::UpdataTable_StandImgPos(QString TableName)
{
	disconnect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	int row = 0;

	for (row = 0; row < m_StandImagePos.size(); row++)
	{
		m_StandImagePos.at(row).x = GetmtfInstance()->QuerySingleValue2Double("conn1", "放料标准图像位置", "图像坐标X", "rowid", QString::number(row + 1));
		m_StandImagePos.at(row).y = GetmtfInstance()->QuerySingleValue2Double("conn1", "放料标准图像位置", "图像坐标Y", "rowid", QString::number(row + 1));
		m_StandImagePos.at(row).R = GetmtfInstance()->QuerySingleValue2Double("conn1", "放料标准图像位置", "角度R", "rowid", QString::number(row + 1));
	}

	for (row = 0; row < m_StandImagePos.size(); row++)
	{
		m_TableObjMap[TableName]->setItemEx("放料顺序", row, QString::number(row + 1));
		m_TableObjMap[TableName]->setItemEx("图像坐标X", row, QString::number(m_StandImagePos.at(row).x));
		m_TableObjMap[TableName]->setItemEx("图像坐标Y", row, QString::number(m_StandImagePos.at(row).y));
		m_TableObjMap[TableName]->setItemEx("角度R", row, QString::number(m_StandImagePos.at(row).R));


		if (row == 0)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "本行及以下是载盘放料标准位");
		}
		else if (row == 24)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "本行及以下是中转位的标准位");
		}
	}
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
}

void ProjectDlg::UpdataTable_RotateCenter(QString TableName)
{
	disconnect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	int row = 0;

	for (row = 0; row < m_RotateCenterImg.size(); row++)
	{
		m_RotateCenterImg.at(row).x = GetmtfInstance()->QuerySingleValue2Double("conn1", "旋转中心", "X坐标", "rowid",QString::number(row+1));
		m_RotateCenterImg.at(row).y = GetmtfInstance()->QuerySingleValue2Double("conn1", "旋转中心", "Y坐标", "rowid", QString::number(row + 1));
	}

	for (row = 0; row < m_RotateCenterImg.size(); row++)
	{
		m_TableObjMap[TableName]->setItemEx("吸嘴号", row, QString::number(row + 1));
		m_TableObjMap[TableName]->setItemEx("图像坐标X", row, QString::number(m_RotateCenterImg.at(row).x));
		m_TableObjMap[TableName]->setItemEx("图像坐标Y", row, QString::number(m_RotateCenterImg.at(row).y));
		if (row == 0)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "本行及以下取料旋转中心");
		}
		else if (row == 6)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "本行及以下放料旋转中心");
		}
	}
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
}

void ProjectDlg::UpdataTable_ManualBC(QString TableName)
{
	disconnect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	int row = 0;

	for (row = 0; row < m_ManualBC.size(); row++)
	{
		m_ManualBC.at(row).x = GetmtfInstance()->QuerySingleValue2Double("conn1", "补偿", "H补偿", "rowid", QString::number(row + 1));
		m_ManualBC.at(row).y = GetmtfInstance()->QuerySingleValue2Double("conn1", "补偿", "W补偿", "rowid", QString::number(row + 1));
		m_ManualBC.at(row).R = GetmtfInstance()->QuerySingleValue2Double("conn1", "补偿", "R补偿", "rowid", QString::number(row + 1));
	}

	for (row = 0; row < m_ManualBC.size(); row++)
	{
		m_TableObjMap[TableName]->setItemEx("序号", row, QString::number(row + 1));
		m_TableObjMap[TableName]->setItemEx("H补偿", row, QString::number(m_ManualBC.at(row).x));
		m_TableObjMap[TableName]->setItemEx("W补偿", row, QString::number(m_ManualBC.at(row).y));
		m_TableObjMap[TableName]->setItemEx("R补偿", row, QString::number(m_ManualBC.at(row).R));

		if (row == 0)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "翘曲度1补偿H(单位mm)");
		}
		else if (row == 1)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "翘曲度2补偿H(单位mm)");
		}
		else if (row == 2)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "备用");
		}
	}
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
}

void ProjectDlg::UpdataTable_ManualBC_Shape(QString TableName)
{
	disconnect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	int row = 0;
	for (row = 0; row < m_ShapeParaBC.size(); row++)
	{
		m_ShapeParaBC.at(row).P0 = GetmtfInstance()->QuerySingleValue2Double("conn1", "变形补偿", "Width1", "rowid", QString::number(row+1));
		m_ShapeParaBC.at(row).P1 = GetmtfInstance()->QuerySingleValue2Double("conn1", "变形补偿", "Width2", "rowid", QString::number(row + 1));
		m_ShapeParaBC.at(row).P2 = GetmtfInstance()->QuerySingleValue2Double("conn1", "变形补偿", "Width3", "rowid", QString::number(row + 1));
		m_ShapeParaBC.at(row).P3 = GetmtfInstance()->QuerySingleValue2Double("conn1", "变形补偿", "Width4", "rowid", QString::number(row + 1));
		m_ShapeParaBC.at(row).P4 = GetmtfInstance()->QuerySingleValue2Double("conn1", "变形补偿", "R1", "rowid", QString::number(row + 1));
		m_ShapeParaBC.at(row).P5 = GetmtfInstance()->QuerySingleValue2Double("conn1", "变形补偿", "R2", "rowid", QString::number(row + 1));
		m_ShapeParaBC.at(row).P6 = GetmtfInstance()->QuerySingleValue2Double("conn1", "变形补偿", "R3", "rowid", QString::number(row + 1));
		m_ShapeParaBC.at(row).P7 = GetmtfInstance()->QuerySingleValue2Double("conn1", "变形补偿", "R4", "rowid", QString::number(row + 1));
	}

	for (row = 0; row < m_ShapeParaBC.size(); row++)
	{
		m_TableObjMap[TableName]->setItemEx("序号", row, QString::number(row + 1));
		m_TableObjMap[TableName]->setItemEx("Width1", row, QString::number(m_ShapeParaBC.at(row).P0));
		m_TableObjMap[TableName]->setItemEx("Width2", row, QString::number(m_ShapeParaBC.at(row).P1));
		m_TableObjMap[TableName]->setItemEx("Width3", row, QString::number(m_ShapeParaBC.at(row).P2));
		m_TableObjMap[TableName]->setItemEx("Width4", row, QString::number(m_ShapeParaBC.at(row).P3));
		m_TableObjMap[TableName]->setItemEx("R1", row, QString::number(m_ShapeParaBC.at(row).P4));
		m_TableObjMap[TableName]->setItemEx("R2", row, QString::number(m_ShapeParaBC.at(row).P5));
		m_TableObjMap[TableName]->setItemEx("R3", row, QString::number(m_ShapeParaBC.at(row).P6));
		m_TableObjMap[TableName]->setItemEx("R4", row, QString::number(m_ShapeParaBC.at(row).P7));

		if(row == 0)  m_TableObjMap[TableName]->setItemEx("备注", row, "宽度mm");
	}
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
}

void ProjectDlg::UpdataTable_light(QString TableName)
{
	disconnect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	int row = 0;
	for (row = 0; row < m_LightIntensity.size(); row++)
	{
		m_LightIntensity.at(row).P0 = GetmtfInstance()->QuerySingleValue2Double("conn1", "光源参数", "亮度", "rowid", QString::number(row + 1));
	}

	for (row = 0; row < m_LightIntensity.size(); row++)
	{
		m_TableObjMap[TableName]->setItemEx("位置ID", row, QString::number(row + 1));
		m_TableObjMap[TableName]->setItemEx("亮度", row, QString::number(m_LightIntensity.at(row).P0));

		if (row == 0)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "光源1");
		}
		else if (row == 1)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "光源2");
		}
		else if (row == 2)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "光源3");
		}
		else if (row == 3)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "光源4");
		}
		else if (row == 4)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "预留");
		}
		else if (row == 5)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "预留");
		}
		else if (row == 6)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "预留");
		}


	}
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
}

void ProjectDlg::UpdataTable_AppearencePara(QString TableName)
{
	disconnect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	int row = 0;

	for (row = 0; row < m_AppearencePara.size(); row++)
	{
		m_AppearencePara.at(row).Gray = GetmtfInstance()->QuerySingleValue2Double("conn1", "外观检测参数", "Gray", "rowid", QString::number(row + 1));
		m_AppearencePara.at(row).Len = GetmtfInstance()->QuerySingleValue2Double("conn1", "外观检测参数", "Len", "rowid", QString::number(row + 1));
		m_AppearencePara.at(row).Width = GetmtfInstance()->QuerySingleValue2Double("conn1", "外观检测参数", "Width", "rowid", QString::number(row + 1));
		m_AppearencePara.at(row).Area = GetmtfInstance()->QuerySingleValue2Double("conn1", "外观检测参数", "Area", "rowid", QString::number(row + 1));

	}

	for (row = 0; row < m_AppearencePara.size(); row++)
	{
		if(row==0) m_TableObjMap[TableName]->setItemEx("类别", row, "Edge");
		if (row == 1) m_TableObjMap[TableName]->setItemEx("类别", row, "Front");
		m_TableObjMap[TableName]->setItemEx("Gray", row, QString::number(m_AppearencePara.at(row).Gray));
		m_TableObjMap[TableName]->setItemEx("Len", row, QString::number(m_AppearencePara.at(row).Len));
		m_TableObjMap[TableName]->setItemEx("Width", row, QString::number(m_AppearencePara.at(row).Width));
		m_TableObjMap[TableName]->setItemEx("Area", row, QString::number(m_AppearencePara.at(row).Area));
		m_TableObjMap[TableName]->setItemEx("备注", row, "Len/Width单位um");
	}

	for (row = 0; row < m_AppearencePara.size(); row++)
	{
		m_Gray[row] = m_AppearencePara.at(row).Gray;
		m_Len[row] = m_AppearencePara.at(row).Len;
		m_Width[row] = m_AppearencePara.at(row).Width;
		m_Area[row] = m_AppearencePara.at(row).Area;

	}
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
}

void ProjectDlg::UpdataTable_ControlPara(QString TableName)
{
	disconnect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	int row = 0;
	for (row = 0; row < m_ControlPara.size(); row++)
	{
		m_ControlPara.at(row).P0= GetmtfInstance()->QuerySingleValue2Double("conn1", "图像控制参数","值","rowid", QString::number(row + 1));
	}
	for (row = 0; row < m_ControlPara.size(); row++)
	{
		m_TableObjMap[TableName]->setItemEx("位置ID", row, QString::number(row + 1));
		m_TableObjMap[TableName]->setItemEx("值", row, QString::number(m_ControlPara.at(row).P0));

		if (row == 0)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "1号相机");
		}
		else if (row == 1)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "2号相机");
		}
		else if (row == 2)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "3号相机");
		}
		else if (row == 3)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "4号相机");
		}
	}
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
}

void ProjectDlg::UpdataTable_NozzleHight(QString TableName)
{
	disconnect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	int row = 0;
	for (row = 0; row < m_NozzleHight.size(); row++)
	{
		m_NozzleHight.at(row).P0 = GetmtfInstance()->QuerySingleValue2Double("conn1", "吸嘴高度", "高度", "rowid", QString::number(row + 1));
	}

	for (row = 0; row < m_NozzleHight.size(); row++)
	{
		m_TableObjMap[TableName]->setItemEx("位置ID", row, QString::number(row + 1));
		m_TableObjMap[TableName]->setItemEx("高度", row, QString::number(m_NozzleHight.at(row).P0));

		if (row == 0)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "放料位1高度，单位um");
		}
		else if (row == 1)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "放料位2高度，单位um");
		}
	}
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
}

void ProjectDlg::UpdataTable_CameraPara(QString TableName)
{
	disconnect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	int row = 0;
	for (row = 0; row < m_CameraPara.size(); row++)
	{
		m_CameraPara.at(row).P0 = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机参数", "曝光", "rowid", QString::number(row + 1));
		m_CameraPara.at(row).P1 = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机参数", "增益", "rowid", QString::number(row + 1));
		m_CameraPara.at(row).P2 = GetmtfInstance()->QuerySingleValue2Double("conn1", "相机参数", "伽马", "rowid", QString::number(row + 1));
	}

	for (row = 0; row < m_CameraPara.size(); row++)
	{
		m_TableObjMap[TableName]->setItemEx("相机ID", row, QString::number(row + 1));
		m_TableObjMap[TableName]->setItemEx("曝光", row, QString::number(m_CameraPara.at(row).P0));
		m_TableObjMap[TableName]->setItemEx("增益", row, QString::number(m_CameraPara.at(row).P1));
		m_TableObjMap[TableName]->setItemEx("伽马", row, QString::number(m_CameraPara.at(row).P2));

		if (row == 0)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "1号相机");
		}
		else if (row == 1)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "2号相机");
		}
		else if (row == 2)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "3号相机");
		}
		else if (row == 3)
		{
			m_TableObjMap[TableName]->setItemEx("备注", row, "4号相机");
		}
	}
	connect(m_TableObjMap[TableName], &MyTableWidget::cellChanged, this, &ProjectDlg::OnEditTable);
	InitCameraPara();//
}

void ProjectDlg::OnPushButton()
{
	QPushButton* pbtn = qobject_cast<QPushButton*>(sender());
	QString btnName = pbtn->objectName();
	if (btnName == "btn_send_plc")
	{
		//int i = ui->cbx_cmd_plc->currentIndex();
		//QString connName = ui->cbx_ConnName_plc->currentText();
		//StFixedData data = m_pSktLinkMaster->Str2Cmd(m_vecPlcCmdSet.at(i));
		//m_pSktLinkMaster->SendData(data, connName);
		//ui->textBrowser_dispCmd->append((m_pSktLinkMaster->Cmd2Str(data)).toStdString().data());
	}
	else if (btnName == "btn_FreshCmd_plc")
	{
		ReadCmdPlc();
	}
	else if (btnName == "btn_load_cmd")
	{
		m_PlcCmdPath = QFileDialog::getOpenFileName(0, "选择命令文件", Pgv::getPlcCmdDirPath(), "*.txt");
		if (!m_PlcCmdPath.contains(".txt"))  return;
		ui->textBrowser_CmdPath->setText(m_PlcCmdPath);
	}
	else if (btnName == "btn_openfolder_cmd")
	{
		QDesktopServices::openUrl(QUrl::fromLocalFile(m_PlcCmdPath));
	}
}

void ProjectDlg::InitProjectPara()
{
	m_pwnd[0] = pgf::GetSetDispFormMap()["Form_0"];
	m_pwnd[1] = pgf::GetSetDispFormMap()["Form_1"];
	m_pwnd[2] = pgf::GetSetDispFormMap()["Form_2"];
	m_pwnd[3] = pgf::GetSetDispFormMap()["Form_3"];
	m_pwnd[4] = pgf::GetSetDispFormMap()["Form_4"];
	m_pwnd[5] = pgf::GetSetDispFormMap()["Form_5"];
	m_pwnd[6] = pgf::GetSetDispFormMap()["Form_6"];
	m_pwnd[7] = pgf::GetSetDispFormMap()["Form_7"];

	LoadCalibFile();
}


//收到客户端请求， 服务端回复客户端请求时触发信号：=================================================================================================
void ProjectDlg::OnRecvRegist(_SocketLinkData data, bool bCheckTimeOut /*= false*/)
{
	//m_pSktLinkMaster->ReRegist(data, 0);
	//m_pDispInfoDlg->LightStatus(m_pDispInfoDlg->m_pBtnStatePLc, 1);
	////m_TimerId_heart = startTimer(1000 * Icg::getIntervalHeart());

	//QString text = QString((char*)data.msg);
	//int count = ui->cbx_ConnName_plc->count();
	//bool bfind = false;
	//for (int i = 0; i < count; i++)
	//{
	//	if (text == ui->cbx_ConnName_plc->itemText(i))
	//	{
	//		bfind = true;
	//	}
	//}
	//if (bfind)	ui->cbx_ConnName_plc->addItem(text);
	//ui->cbx_ConnName_plc->setCurrentText(text);
}

void ProjectDlg::WatchCameraTriggred(_SocketLinkData data)
{
	auto start = GetmtfInstance()->GetTimeNow();
	m_bStartWatchTriggred = true;

	QString strCamNum;
	if (m_bWillPhoto[0])
	{
		strCamNum += " [1] ";
	}
	if (m_bWillPhoto[1])
	{
		strCamNum += " [2] ";
	}
	if (m_bWillPhoto[2])
	{
		strCamNum += " [3] ";
	}
	if (m_bWillPhoto[3])
	{
		strCamNum += " [4] ";
	}

	while (true)
	{
		if (m_bWillPhoto[0] == m_bCameraTriggred[0]
			&& m_bWillPhoto[1] == m_bCameraTriggred[1]
			&& m_bWillPhoto[2] == m_bCameraTriggred[2]
			&& m_bWillPhoto[3] == m_bCameraTriggred[3])
		{
			gthpool->AddTask(std::bind(&ProjectDlg::ImgProcess, m_pThis,
				m_bCameraTriggred[0], m_bCameraTriggred[1], m_bCameraTriggred[2], m_bCameraTriggred[3], strCamNum));

			if (!m_pThis->m_bShieldComm)
				//m_pSktLinkMaster->PhotographDone(m_bCameraTriggred[0], m_bCameraTriggred[1], m_bCameraTriggred[2], m_bCameraTriggred[3]);

			//lockup(m_pThis->m_PhotographDoneMutex);
			for (int i = 0; i < 4; i++)
			{
				m_bWillPhoto[i] = false;
				m_bCameraTriggred[i] = false;
			}
			m_bStartWatchTriggred = false;


			auto end = GetmtfInstance()->GetTimeNow();
			double durationTime = GetmtfInstance()->durationTime(end, start, TimeType::second);
			LOG_DEBUG(glogger, MultUtf82Mult2(strCamNum + "号相机拍照完成,耗时：") << durationTime);
			break;
		}
		auto end = GetmtfInstance()->GetTimeNow();
		double durationTime = GetmtfInstance()->durationTime(end, start, TimeType::second);
		if (durationTime > 10)
		{
			LOG_DEBUG(glogger, MultUtf82Mult2(strCamNum + "号相机拍照超时！"));
			//m_pSktLinkMaster->PhotographDone(m_bCameraTriggred[0], m_bCameraTriggred[1], m_bCameraTriggred[2], m_bCameraTriggred[3], 1);

			for (int i = 0; i < 4; i++)
			{
				m_bWillPhoto[i] = false;
				m_bCameraTriggred[i] = false;
			}
			m_bStartWatchTriggred = false;

			return;
		}
		//mSleep(5);
	}
}

void ProjectDlg::ImgProcess(bool bTriggred1, bool bTriggred2, bool bTriggred3, bool bTriggred4, QString strCamNum)
{
	auto start = GetmtfInstance()->GetTimeNow();
	_ImgRsult temp[4];
	std::future<_ImgRsult> res[4];

	if (bTriggred1)
	{
		res[0] = gthpool->AddTask(std::bind(&ProjectDlg::ImgProcessHight1, m_pThis, m_CameraImg[0], 1));
	}
	if (bTriggred2)
	{
		res[1] = gthpool->AddTask(std::bind(&ProjectDlg::ImgProcessFront, m_pThis, m_CameraImg[1], 2));
	}
	if (bTriggred3)
	{
		res[2] = gthpool->AddTask(std::bind(&ProjectDlg::ImgProcessHight2, m_pThis, m_CameraImg[2], 3));
	}
	if (bTriggred4)
	{
		res[3] = gthpool->AddTask(std::bind(&ProjectDlg::ImgProcessDeformation, m_pThis, m_CameraImg[3], 4));
	}

	if (bTriggred1) temp[0] = res[0].get();
	else temp[0].P[0] = 3;
	if (bTriggred2) temp[1] = res[1].get();
	else temp[1].P[0] = 3;
	if (bTriggred3) temp[2] = res[2].get();
	else temp[2].P[0] = 3;
	if (bTriggred4) temp[3] = res[3].get();
	else temp[3].P[0] = 3;
	auto end = GetmtfInstance()->GetTimeNow();
	double durationTime = GetmtfInstance()->durationTime(end, start, TimeType::second);
	//if (!m_bTriggerTest && !m_bManualTriggerTest) m_pSktLinkMaster->ProcessImageResult(temp[0].P[0], temp[1].P[0], temp[2].P[0], temp[3].P[0]);
	LOG_DEBUG(glogger, MultUtf82Mult2(strCamNum + "号相机图像处理完成,耗时：") << durationTime);
}

void ProjectDlg::ImgProcess1(QString strCamNum)
{
	if (!m_bAdjustNozzleModel)
	{
		if (m_pThis->m_ProductType != "Manual")
		{
			auto start = GetmtfInstance()->GetTimeNow();
			_ImgRsult temp;
			std::future<_ImgRsult> res;
			res = gthpool->AddTask(std::bind(&ProjectDlg::ImgProcessHight1, m_pThis, m_CameraImg[0], 1));
			temp = res.get();
			auto end = GetmtfInstance()->GetTimeNow();
			double durationTime = GetmtfInstance()->durationTime(end, start, TimeType::second);
			QString res2 = m_pSktLinkMaster->WriteShortRegister(CamResult1, QString::number(temp.P[0]));
			LOG_DEBUG(glogger, MultUtf82Mult2(strCamNum + "号相机图像处理完成,耗时：") << durationTime);
			if (m_bWorkingAuto)
			{
				temp.P[1] = strCamNum.toInt();
				ImgResultAnalysis(temp);
			}
		}
		else if (m_pThis->m_ProductType == "Manual")
		{
			if (m_pQDrawDlg != nullptr) m_pQDrawDlg->OnClearMeasure();
			m_ImgHigh1 = m_CameraImg[0];
			DlgDispImg(m_pwnd[0], "", m_ImgHigh1);
		}
	}
	else
	{
		auto start = GetmtfInstance()->GetTimeNow();
		_ImgRsult temp;
		std::future<_ImgRsult> res;
		res = gthpool->AddTask(std::bind(&ProjectDlg::AdjsutNozzel1, m_pThis, m_CameraImg[0], 1));
		temp = res.get();
		auto end = GetmtfInstance()->GetTimeNow();
		double durationTime = GetmtfInstance()->durationTime(end, start, TimeType::second);
		QString res2 = m_pSktLinkMaster->WriteLongRegister(NozzleHight1, QString::number(temp.P[0]));
		LOG_DEBUG(glogger, MultUtf82Mult2(strCamNum + "号相机吸嘴高度调节图像处理完成,耗时：") << durationTime);

	}
}

void ProjectDlg::ImgProcess2(QString strCamNum)
{
	auto start = GetmtfInstance()->GetTimeNow();
	_ImgRsult temp;
	std::future<_ImgRsult> res;
	res = gthpool->AddTask(std::bind(&ProjectDlg::ImgProcessFront, m_pThis, m_CameraImg[1], 2));
	temp = res.get();
	auto end = GetmtfInstance()->GetTimeNow();
	double durationTime = GetmtfInstance()->durationTime(end, start, TimeType::second);
	QString res2 = m_pSktLinkMaster->WriteShortRegister(CamResult2, QString::number(temp.P[0]));
	LOG_DEBUG(glogger, MultUtf82Mult2(strCamNum + "号相机图像处理完成,耗时：") << durationTime);
	if (m_bWorkingAuto)
	{
		temp.P[1] = strCamNum.toInt();
		ImgResultAnalysis(temp);
	}
}

void ProjectDlg::ImgProcess3(QString strCamNum)
{
	if (!m_bAdjustNozzleModel)
	{
		auto start = GetmtfInstance()->GetTimeNow();
		_ImgRsult temp;
		std::future<_ImgRsult> res;
		res = gthpool->AddTask(std::bind(&ProjectDlg::ImgProcessHight2, m_pThis, m_CameraImg[2], 3));
		temp = res.get();
		auto end = GetmtfInstance()->GetTimeNow();
		double durationTime = GetmtfInstance()->durationTime(end, start, TimeType::second);
		QString res2 = m_pSktLinkMaster->WriteShortRegister(CamResult3, QString::number(temp.P[0]));
		LOG_DEBUG(glogger, MultUtf82Mult2(strCamNum + "号相机图像处理完成,耗时：") << durationTime);
		if (m_bWorkingAuto)
		{
			temp.P[1] = strCamNum.toInt();
			ImgResultAnalysis(temp);
		}
	}
	else {
		auto start = GetmtfInstance()->GetTimeNow();
		_ImgRsult temp;
		std::future<_ImgRsult> res;
		res = gthpool->AddTask(std::bind(&ProjectDlg::AdjsutNozzel2, m_pThis, m_CameraImg[2], 3));
		temp = res.get();
		auto end = GetmtfInstance()->GetTimeNow();
		double durationTime = GetmtfInstance()->durationTime(end, start, TimeType::second);
		QString res2 = m_pSktLinkMaster->WriteLongRegister(NozzleHight2, QString::number(temp.P[0]));
		LOG_DEBUG(glogger, MultUtf82Mult2(strCamNum + "号相机吸嘴高度调节图像处理完成,耗时：") << durationTime);

	}

}

void ProjectDlg::ImgProcess4(QString strCamNum)
{
	auto start = GetmtfInstance()->GetTimeNow();
	_ImgRsult temp;
	std::future<_ImgRsult> res;
	res = gthpool->AddTask(std::bind(&ProjectDlg::ImgProcessDeformation, m_pThis, m_CameraImg[3], 4));
	temp = res.get();
	auto end = GetmtfInstance()->GetTimeNow();
	double durationTime = GetmtfInstance()->durationTime(end, start, TimeType::second);
	QString res2 = m_pSktLinkMaster->WriteShortRegister(CamResult4, QString::number(temp.P[0]));
	LOG_DEBUG(glogger, MultUtf82Mult2(strCamNum + "号相机图像处理完成,耗时：") << durationTime);
	if (m_bWorkingAuto) 
	{
		temp.P[1] = strCamNum.toInt();
		ImgResultAnalysis(temp);
	} 
}

void ProjectDlg::ImgResultAnalysis(_ImgRsult res)
{
	lockup(m_vecImgResultMutex);
	m_vecImgResult.push_back(res);
	if (m_vecImgResult.size() != 4) return;
	auto start = GetmtfInstance()->GetTimeNow();
	_ImgRsult szTemp[4];
	for (int i = 0; i < 4; i++)
	{
		if (m_vecImgResult.at(i).P[1] == 1)
			szTemp[0] = m_vecImgResult.at(i);
		else if (m_vecImgResult.at(i).P[1] == 2)
			szTemp[1] = m_vecImgResult.at(i);
		else if (m_vecImgResult.at(i).P[1] == 3)
			szTemp[2] = m_vecImgResult.at(i);
		else if (m_vecImgResult.at(i).P[1] == 4)
			szTemp[3] = m_vecImgResult.at(i);
	}
	m_vecImgResult.clear();

	m_SZImgResult[0] = m_SZImgResult[6];
	m_SZImgResult[1] = m_SZImgResult[7];
	m_SZImgResult[2] = szTemp[2];
	m_SZImgResult[3] = szTemp[3];

	m_SZImgResult[6] = m_SZImgResult[4];
	m_SZImgResult[7] = m_SZImgResult[5];
	m_SZImgResult[4] = szTemp[0];
	m_SZImgResult[5] = szTemp[1];


	QString strResult = "";
	//if (m_SZImgResult[0].P[0] == 1 && m_SZImgResult[1].P[0] == 1 && m_SZImgResult[2].P[0] == 1 && m_SZImgResult[3].P[0] == 1)
	//{
	//	strResult = "OK";
	//	QString res = m_pSktLinkMaster->WriteShortRegister(CamResultALL, QString::number(1));
	//}
	//else
	//{
	//	strResult = "NG";
	//	QString res = m_pSktLinkMaster->WriteShortRegister(CamResultALL, QString::number(0));
	//}

	if ((m_SZImgResult[0].P[0] == 1 && m_SZImgResult[1].P[0] == 1 && m_SZImgResult[2].P[0] == 1 && m_SZImgResult[3].P[0] == 1)||
		(m_SZImgResult[0].P[0] == 0 && m_SZImgResult[1].P[0] == 1 && m_SZImgResult[2].P[0] == 1 && m_SZImgResult[3].P[0] == 1)||
		(m_SZImgResult[0].P[0] == 1 && m_SZImgResult[1].P[0] == 1 && m_SZImgResult[2].P[0] ==0  && m_SZImgResult[3].P[0] == 1))
	{
		strResult = "OK";
		QString res = m_pSktLinkMaster->WriteShortRegister(CamResultALL, QString::number(1));
	}
	else
	{
		strResult = "NG";
		QString res = m_pSktLinkMaster->WriteShortRegister(CamResultALL, QString::number(0));
	}


	if (0/*vecTemp[2].P[0]==2 || vecTemp[3].P[0] == 2 || Result[0].P[0] == 2 || Result[1].P[0] == 2*/)//1、2、3、4号相机无产品
	{
		emit postShowData(false, m_SZImgResult[0].str[2], m_SZImgResult[1].str[0], m_SZImgResult[2].str[2], m_SZImgResult[3].str[0], strResult);
	}
	else
	{
		emit postShowData(true, m_SZImgResult[0].str[2], m_SZImgResult[1].str[0], m_SZImgResult[2].str[2], m_SZImgResult[3].str[0], strResult);
		QDateTime DateTime = QDateTime::currentDateTime();
		QString strProcessDate = DateTime.date().toString("yyyy-MM-dd");
		QString strTimeId = DateTime.toString("hhmmss");
		QString strTimeDot = DateTime.time().toString("hh:mm:ss");

		auto fun = [=] {
			QString FolderPath = m_CsvFolderPath + "/" + strProcessDate + "/" + m_ProductType;
			if (!GetmtfInstance()->isFolderExist(FolderPath))
			{
				GetmtfInstance()->CreateExteriorFolder(FolderPath);
			}
			QString filePath = FolderPath + "/总检测结果" + m_ProductType + ".csv";
			if (!GetmtfInstance()->isFileExist(filePath))
			{
				WriteImgResultCsvHeader(filePath);
			}

			QString strResult1, strResult10, strResult2, strResult20;
			QString strRes = m_SZImgResult[0].str[1];
			if (strRes == "OK")
			{
				strResult1 = strRes;
				strResult10 = strRes;
			}
			else if (strRes == "HeightNG")
			{
				strResult1 = "NG";
				strResult10 = "OK";
			}
			else if (strRes == "WarPageNG")
			{
				strResult1 = "OK";
				strResult10 = "NG";
			}
			else if (strRes == "HeightWarPageNG")
			{
				strResult1 = "NG";
				strResult10 = "NG";
			}
			else
			{
				strResult1 = strRes;
				strResult10 = strRes;
			}

			strRes = m_SZImgResult[2].str[1];
			if (strRes == "OK")
			{
				strResult2 = strRes;
				strResult20 = strRes;
			}
			else if (strRes == "HeightNG")
			{
				strResult2 = "NG";
				strResult20 = "OK";
			}
			else if (strRes == "WarPageNG")
			{
				strResult2 = "OK";
				strResult20 = "NG";
			}
			else if (strRes == "HeightWarPageNG")
			{
				strResult2 = "NG";
				strResult20 = "NG";
			}
			else
			{
				strResult2 = strRes;
				strResult20 = strRes;
			}


			WriteImgResultCsvData(strTimeDot,
				m_SZImgResult[0].str[0], strResult1,
				m_SZImgResult[0].str[2], m_SZImgResult[0].str[3], m_SZImgResult[0].str[4], strResult10,
				m_SZImgResult[1].str[0],
				m_SZImgResult[2].str[0], strResult2,
				m_SZImgResult[2].str[2], m_SZImgResult[2].str[3], m_SZImgResult[2].str[4], strResult20,
				m_SZImgResult[3].str[0], strResult, filePath);
		};
		gthpool->AddTask(fun);
	}
	auto end = GetmtfInstance()->GetTimeNow();
	double durationTime = GetmtfInstance()->durationTime(end, start, TimeType::second);
	LOG_DEBUG(glogger, MultUtf82Mult2("========图像处理结果分析完成,耗时：") << durationTime);
}


//void ProjectDlg::ImgResultAnalysis(_ImgRsult res)
//{
//	lockup(m_vecImgResultMutex);
//	m_vecImgResult.push_back(res);
//	if (m_vecImgResult.size() != 4) return;
//		auto start = GetmtfInstance()->GetTimeNow();
//		_ImgRsult szTemp[4];
//		for (int i=0;i<4;i++)
//		{
//			if(m_vecImgResult.at(i).P[1]==1)
//			     szTemp[0]=m_vecImgResult.at(i);
//			else if (m_vecImgResult.at(i).P[1] == 2)
//				szTemp[1] = m_vecImgResult.at(i);
//			else if (m_vecImgResult.at(i).P[1] == 3)
//				szTemp[2] = m_vecImgResult.at(i);
//			else if (m_vecImgResult.at(i).P[1] == 4)
//				szTemp[3] = m_vecImgResult.at(i);
//		}
//		m_vecImgResult.clear();
//
//		m_SZImgResult[0] = m_SZImgResult[4];
//		m_SZImgResult[1] = m_SZImgResult[5];
//		m_SZImgResult[2] = szTemp[2];
//		m_SZImgResult[3] = szTemp[3];
//		m_SZImgResult[4] = szTemp[0];
//		m_SZImgResult[5] = szTemp[1];
//
//		QString strResult = "";
//		if (m_SZImgResult[0].P[0]==1 && m_SZImgResult[1].P[0] == 1 && m_SZImgResult[2].P[0] == 1 && m_SZImgResult[3].P[0] == 1)
//		{
//			strResult = "OK";
//		}
//		else
//		{
//			strResult = "NG";
//		}
//
//		if (0/*vecTemp[2].P[0]==2 || vecTemp[3].P[0] == 2 || Result[0].P[0] == 2 || Result[1].P[0] == 2*/)//1、2、3、4号相机无产品
//        {
//			emit postShowData(false, m_SZImgResult[0].str[2], m_SZImgResult[1].str[0], m_SZImgResult[2].str[2], m_SZImgResult[3].str[0], strResult);
//		}
//		else
//		{
//			emit postShowData(true, m_SZImgResult[0].str[2], m_SZImgResult[1].str[0], m_SZImgResult[2].str[2], m_SZImgResult[3].str[0], strResult);	
//			QDateTime DateTime = QDateTime::currentDateTime();
//			QString strProcessDate = DateTime.date().toString("yyyy-MM-dd");
//			QString strTimeId = DateTime.toString("hhmmss");
//			QString strTimeDot = DateTime.time().toString("hh:mm:ss");
//
//			auto fun = [=] {
//			QString FolderPath = m_CsvFolderPath + "/" + strProcessDate + "/" + m_ProductType;
//			if (!GetmtfInstance()->isFolderExist(FolderPath))
//			{
//				GetmtfInstance()->CreateExteriorFolder(FolderPath);
//			}
//			QString filePath = FolderPath  + "/总检测结果"+m_ProductType+".csv";
//			if (!GetmtfInstance()->isFileExist(filePath))
//			{
//				WriteImgResultCsvHeader(filePath);
//			}
//
//			QString strResult1, strResult10, strResult2, strResult20;
//			QString strRes =m_SZImgResult[0].str[1];
//			if (strRes == "OK")
//			{
//				strResult1 = strRes;
//				strResult10 = strRes;	
//			}
//			else if (strRes == "HeightNG")
//			{
//				strResult1 = "NG";
//				strResult10 = "OK";
//			}
//			else if (strRes == "WarPageNG")
//			{
//				strResult1 = "OK";
//				strResult10 = "NG";
//			}
//			else if (strRes == "HeightWarPageNG")
//			{
//				strResult1 = "NG";
//				strResult10 = "NG";
//			}
//			else
//			{
//				strResult1 = strRes;
//				strResult10 = strRes;
//			}
//
//			strRes = m_SZImgResult[2].str[1];
//			if (strRes == "OK")
//			{
//				strResult2 = strRes;
//				strResult20 = strRes;
//			}
//			else if (strRes == "HeightNG")
//			{
//				strResult2 = "NG";
//				strResult20 = "OK";
//			}
//			else if (strRes == "WarPageNG")
//			{
//				strResult2 = "OK";
//				strResult20 = "NG";
//			}
//			else if (strRes == "HeightWarPageNG")
//			{
//				strResult2 = "NG";
//				strResult20 = "NG";
//			}
//			else
//			{
//				strResult2 = strRes;
//				strResult20 = strRes;
//			}
//
//
//			WriteImgResultCsvData(strTimeDot, 
//				m_SZImgResult[0].str[0], strResult1,
//				m_SZImgResult[0].str[2], m_SZImgResult[0].str[3], m_SZImgResult[0].str[4], strResult10,
//				m_SZImgResult[1].str[0], 
//				m_SZImgResult[2].str[0], strResult2,
//				m_SZImgResult[2].str[2], m_SZImgResult[2].str[3], m_SZImgResult[2].str[4], strResult20,
//				m_SZImgResult[3].str[0], strResult, filePath);
//			};
//			gthpool->AddTask(fun);
//		}
//		auto end = GetmtfInstance()->GetTimeNow();
//		double durationTime = GetmtfInstance()->durationTime(end, start, TimeType::second);
//		LOG_DEBUG(glogger, MultUtf82Mult2("========图像处理结果分析完成,耗时：") << durationTime);
//}

void ProjectDlg::InitTestResultStatus()
{
	lockup(m_vecImgResultMutex);
	m_vecImgResult.clear();
	QString res = m_pSktLinkMaster->WriteShortRegister(CamResultALL, QString::number(0));
	_ImgRsult Temp;
	for(int i=0;i<8;i++)
	{
		m_SZImgResult[i] = Temp;
	}
}

void ProjectDlg::OnRecvRecvWarning(_SocketLinkData data, bool bCheckTimeOut /*= false*/)
{
	int WarningNum = data.Param0.toInt();//报警编号
	int iSWarning = data.Param1.toInt();//0是发生报警，1是消除报警

	LOG_INFO(glogger, MultUtf82Mult2("报警请求回复完成"));
	auto fun = [=] {
		QDateTime DateTime = QDateTime::currentDateTime();
		QString strDateTime = DateTime.toString("yyyy-MM-dd_hh_mm_ss");
		QString strDate = DateTime.date().toString("yyyy-MM-dd");
		//QString strTime = DateTime.time().toString("hh_mm_ss");
		QString strTimeDot = DateTime.time().toString("hh:mm:ss");
		QString connName = DateTime.time().toString("hhmmsszzz");
		m_pProjectDB->CreateProjectDataConnection(connName);
		lockup(m_WritePLCWarningCsvMutex);
		QString FolderPath = m_PlcLogDataFolderPath;
		if (!GetmtfInstance()->isFolderExist(FolderPath))
		{
			GetmtfInstance()->CreateExteriorFolder(FolderPath);
		}
		QString filePath = FolderPath + "/" + strDate + ".csv";
		if (!GetmtfInstance()->isFileExist(filePath))
		{
			WritePLCWarningCsvHeader(filePath);
		}
		if (iSWarning == 0)
		{
			WritePLCWarningCsvData(strTimeDot, WarningNum, m_WarningMap[WarningNum], filePath);
			m_pProjectDB->WriteLogDB(connName, WarningNum, m_WarningMap[WarningNum]);
			LOG_INFO(glogger, MultUtf82Mult2("PLC发起编号") << WarningNum << MultUtf82Mult2("的报警：") << MultUtf82Mult(m_WarningMap[WarningNum]));
		}
		else
		{
			WritePLCWarningCsvData(strTimeDot,0,"PLC报警解除", filePath);
			m_pProjectDB->WriteLogDB(connName,0, "PLC报警解除");
			LOG_INFO(glogger, MultUtf82Mult2("PLC报警解除"));
		}
		m_pProjectDB->removeConnection(connName);
	};
	gthpool->AddTask(fun);
}

void ProjectDlg::OnRecvEquipmentState(_SocketLinkData data, bool bCheckTimeOut /*= false*/)
{
	INT32 result = data.Param0.toInt();
	if (result == 3)//手动中
	{
		m_bWorkingAuto = false;
		InitTestResultStatus();
	}
	else if (result==0)//自动中
	{
		InitTestResultStatus();
		m_bWorkingAuto = true;
		m_pDispInfoDlg->m_bWorking = true;
		m_pDispInfoDlg->m_bWarning = false;
		m_pDispInfoDlg->m_bWaitting = false;
	} 
	else if (result == 1)//报警
	{
		m_bWorkingAuto = false;
		m_pDispInfoDlg->m_bWorking = false;
		m_pDispInfoDlg->m_bWarning = true;
		m_pDispInfoDlg->m_bWaitting = false;
	}
	else if (result == 2)//待料
	{
		m_bWorkingAuto = true;
		m_pDispInfoDlg->m_bWorking = false;
		m_pDispInfoDlg->m_bWarning = false;
		m_pDispInfoDlg->m_bWaitting = true;
	}
}

void ProjectDlg::OnRecvChangeProduct(_SocketLinkData data, bool bCheckTimeOut /*= false*/)
{
	int index = data.Param0.toInt();
	//ui->comboBox_RingType->setCurrentIndex(index);
}

bool  ProjectDlg::GetImg(sptr<HObject>& obj, QString CameraName, int CameraIndex, int PictureIndex, int GroupIndex)
{
	if (!m_bSimulate && (Pgv::getControlNum() != 0))//光源
	{
		if ((pSimulateCam != nullptr) || (pSimulateCam->GetSiCamMap()[CameraIndex][PictureIndex] != nullptr))
		{
			MessageBoxTip("请切换仿真模式");
			return false;
		}
		int channel[2];
		int time[2] = { 50,50 };
		if (GroupIndex <= 1)
		{
			channel[0] = m_vecLightChannel.at(0);
			channel[1] = m_vecLightChannel.at(1);
			Pgv::getNameControlMap()[CTRL_NAME_0]->SoftwareMultiTrigger(channel, time, 2);
		}
		else if (!m_bTriggerTest && 2<=GroupIndex && GroupIndex <= 3)
		{
			channel[0] = m_vecLightChannel.at(2);
			channel[1] = m_vecLightChannel.at(3);
			Pgv::getNameControlMap()[CTRL_NAME_0]->SoftwareMultiTrigger(channel, time, 2);
		}
		else if (4 <= GroupIndex && GroupIndex <= 5)
		{
			int channel[1] = { m_vecLightChannel.at(0) };
			int time[1] = {50};
			if(Pgv::getNameControlMap()[CTRL_NAME_1]!=nullptr) Pgv::getNameControlMap()[CTRL_NAME_1]->SoftwareMultiTrigger(channel, time, 1);
		}
	}
	//相机=======================================================================================
	if (!m_bSimulate)
	{
		if ((pSimulateCam != nullptr) || (pSimulateCam->GetSiCamMap()[CameraIndex][PictureIndex] != nullptr))
		{
			MessageBoxTip("请切换仿真模式");
			return false;
		}
		Pgv::getNameCameraMap()[CameraName]->GetSingleImage(obj);
	}
	else
	{
		if (pSimulateCam == nullptr || pSimulateCam->GetSiCamMap()[CameraIndex][PictureIndex] == nullptr)
		{
			MessageBoxTip("请先打开仿真相机");
			return false;
		}
		pSimulateCam->GetSiCamMap()[CameraIndex][PictureIndex]->GetSingleImage(obj);
	}
	return true;
}

bool ProjectDlg::SoftTrggerCam(QString CameraName, int CameraIndex, int PictureIndex, bool bTriggerProcessImg, std::function<void(sptr<HObject> RtImage, void* pUser)> TriggerCallBackFun, void* pUser)
{
	if (!m_bSimulate)//实体相机
	{
		if ((pSimulateCam != nullptr) || (pSimulateCam->GetSiCamMap()[CameraIndex][PictureIndex] != nullptr))
		{
			MessageBoxTip("请切换仿真模式");
			return false;
		}
		if(Pgv::getNameCameraMap()[CameraName]!=nullptr) Pgv::getNameCameraMap()[CameraName]->trigger();
		else {
			MessageBoxTip("请选择正确实体相机或使用仿真模式！");
			return false;
		}
	}
	else//模拟相机
	{
		if (pSimulateCam == nullptr || pSimulateCam->GetSiCamMap()[CameraIndex][PictureIndex] == nullptr)
		{
			MessageBoxTip("请先打开仿真相机");
			return false;
		}
		pSimulateCam->GetSiCamMap()[CameraIndex][PictureIndex]->RegTriggerCallBackFun(TriggerCallBackFun, pUser);
		pSimulateCam->GetSiCamMap()[CameraIndex][PictureIndex]->m_bProcessImgFrame= bTriggerProcessImg;
		pSimulateCam->GetSiCamMap()[CameraIndex][PictureIndex]->trigger();
	}

	return true;
}

_ImgRsult ProjectDlg::ImgProcessHightManual(sptr<HObject> obj, int CamNo, QDrawDlg* p)
{
	_ImgRsult imgResult;
	m_ImgHigh1 = obj;
	HTuple Height, iResult, iError;
	int DispWindNo = CamNo - 1;
	int iRes = 0;
	int ErrorNo = 0;
	QString text;
	QString picType;
	QString strHeight[7], strResult;

	try {
		m_hdev->GetHeightResultManual(*m_ImgHigh1, *m_HighROI1, *m_OutRegionHigh1, *m_OutXldHigh1, 0, \
			m_ControlPara.at(0).P0, m_ManualBC.at(0).x,
			p->m_lineCoorRow1, p->m_lineCoorColumn1, p->m_lineCoorRow2, p->m_lineCoorColumn2,
			&Height, &iResult, &iError);
		iRes = iResult.I();
		ErrorNo = iError.I();
	}
	catch (...)
	{
		m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
		DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1);
		text = "外部图像处理调用出错！";
		picType = "外部图像处理调用出错";
		Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
		//if(!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Error);
		imgResult.P[0] = (int)IMG_RESULT::Error;

		strHeight[0] = "Error";
		strResult = "Error";
		goto end;
	}

	if (ErrorNo == 0)
	{
		if (iRes==0)//OK
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "green");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1, m_OutRegionHigh1, m_OutXldHigh1);
			text = "厚度：" + QString::number(Height[1].D()) + "mm "
				+ QString::number(Height[2].D()) + "mm "

				"翘曲：" + QString::number(Height[4].D()) + "mm  OK";

			picType = "OK产品";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "green");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::OK);
			imgResult.P[0] = (int)IMG_RESULT::OK;
			strResult = "OK";
			for (int i = 0; i < 7; i++)
			{
				strHeight[i] = QString::number(Height[i].D());
			}
		}
		else //NG
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1, m_OutRegionHigh1, m_OutXldHigh1);
			text = "厚度：" + QString::number(Height[1].D()) + "mm "
				+ QString::number(Height[2].D()) + "mm "

				"翘曲：" + QString::number(Height[4].D()) + "mm  NG";

			picType = "翘曲超出范围";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "WarPageNG";
			for (int i = 0; i < 7; i++)
			{
				strHeight[i] = QString::number(Height[i].D());
			}
		}
	}
	else
	{
		if (ErrorNo == -1)//内部图像处理出错
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1);
			text = "内部图像处理出错！";
			picType = "内部图像处理出错";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Error);
			imgResult.P[0] = (int)IMG_RESULT::Error;
			strHeight[0] = "Error";
			strResult = "Error";
		}
		else if (ErrorNo == -2)//无产品
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1);
			text = "无产品";
			picType = "无产品";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Empty);
			imgResult.P[0] = (int)IMG_RESULT::Empty;
			strResult = "Empty";
			strHeight[0] = "Empty";
		}
	}
end:
	QDateTime DateTime = QDateTime::currentDateTime();
	QString strProcessDate = DateTime.date().toString("yyyy-MM-dd");
	QString strTimeId = DateTime.toString("hhmmss");
	QString strTimeDot = DateTime.time().toString("hh:mm:ss");

	QString picName = "WarPage_" + strTimeId + "_" + strHeight[4];

	if ((!m_bSimulate || m_bSimulateSavePic) && m_bSaveOkPic)
	{
		auto SaveImagefun = [=] {
			QString folderPath = m_PictureFolderPath + "/" + strProcessDate + "/" + m_ProductType + "/翘曲度1图片/" + picType;
			if (m_bSaveOriginalPicture)
			{
				Imgtfc::SaveImage(m_ImgHigh1, picName, folderPath);
			}
			else
			{
				Imgtfc::SaveImageCompression(m_ImgHigh1, picName, folderPath);
			}
		};
		gthpool->AddTask(SaveImagefun);
	}

	auto fun = [=] {
		QString FolderPath = m_CsvFolderPath + "/" + strProcessDate + "/" + m_ProductType;
		if (!GetmtfInstance()->isFolderExist(FolderPath))
		{
			GetmtfInstance()->CreateExteriorFolder(FolderPath);
		}
		QString filePath = FolderPath + "/翘曲度1数据" + m_ProductType + ".csv";
		if (!GetmtfInstance()->isFileExist(filePath))
		{
			WriteHighCsvHeader(filePath);
		}

		QString strResult0, strResult1, strResult2;
		if (strResult=="OK")
		{
			strResult0 = strResult;
			strResult1 = strResult;
			strResult2 = strResult;
		}
		else if (strResult == "WarPageNG")
		{
			strResult0 = "OK";
			strResult1 = "NG";
			strResult2 = "NG";
		}
		else
		{
			strResult0 = strResult;
			strResult1 = strResult;
			strResult2 = strResult;
		}

		WriteHighCsvData(strTimeDot, strHeight[0], strResult0,
			strHeight[1], strHeight[2], strHeight[3],
			strHeight[4], strHeight[5], strHeight[6], strResult1,
			strResult2, filePath);
	};
	gthpool->AddTask(fun);
	//emit postShowData("翘曲1",true, strHeight, strResult, "");
	imgResult.str[0] = strHeight[0];
	imgResult.str[1] = strResult;
	imgResult.str[2] = strHeight[4];
	imgResult.str[3] = strHeight[5];
	imgResult.str[4] = strHeight[6];
	LOG_DEBUG(glogger, MultUtf82Mult2(QString::number(CamNo) + "号相机图像处理完成"));
	return imgResult;
}

_ImgRsult ProjectDlg::AdjsutNozzel1(sptr<HObject> obj, int CamNo)
{
	_ImgRsult imgResult;
	m_ImgHigh1 = obj;
	HTuple Height, iResult, iError;
	int DispWindNo = CamNo - 1;
	int iRes = 1;
	int ErrorNo = 0;
	QString text;
	QString picType;
	int stdHight = m_NozzleHight[0].P0;

	try {
		m_hdev->AdjustNozzleHeight(*m_ImgHigh1, *m_HighROI1, *m_OutRegionHigh1, *m_OutXldHigh1, stdHight, \
		 &Height, &iResult, &iError);
		iRes = iResult.I();
		ErrorNo = iError.I();
	}
	catch (...)
	{
		m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
		DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1);
		text = "外部图像处理调用出错！";
		picType = "外部图像处理调用出错";
		Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
		imgResult.P[0] = 999999;
		goto end;
	}

	if (ErrorNo == 0)
	{
		if (iRes == 0)//OK
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "green");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1, m_OutRegionHigh1, m_OutXldHigh1);
			text = "目标高度1：" + QString::number(Height[1].D()) + "um   "
				"需调整1：" + QString::number(Height[0].D()) + "um";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "green");
			imgResult.P[0] = Height[0].D();
		}
	}
	else
	{
		if (ErrorNo == -1)//内部图像处理出错
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1);
			text = "内部图像处理出错！";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			imgResult.P[0] = 999999;
		}
	}
end:
	QDateTime DateTime = QDateTime::currentDateTime();
	QString strProcessDate = DateTime.date().toString("yyyy-MM-dd");
	QString strTimeId = DateTime.toString("hhmmss");
	QString strTimeDot = DateTime.time().toString("hh:mm:ss");

	QString picName = "NozzelHight1_" + strTimeId;

	if ((!m_bSimulate || m_bSimulateSavePic) && m_bSaveOkPic)
	{
		auto SaveImagefun = [=] {
			QString folderPath = m_PictureFolderPath + "/" + strProcessDate + "/" + m_ProductType + "/高度调节1图片/" + picType;
			if (m_bSaveOriginalPicture)
			{
				Imgtfc::SaveImage(m_ImgHigh1, picName, folderPath);
			}
			else
			{
				Imgtfc::SaveImageCompression(m_ImgHigh1, picName, folderPath);
			}
		};
		gthpool->AddTask(SaveImagefun);
	}
	LOG_DEBUG(glogger, MultUtf82Mult2(QString::number(CamNo) + "号相机高度调节1处理完成"));
	return imgResult;
}

_ImgRsult ProjectDlg::AdjsutNozzel2(sptr<HObject> obj, int CamNo)
{
	_ImgRsult imgResult;
	m_ImgHigh2 = obj;
	HTuple Height, iResult, iError;
	int DispWindNo = CamNo - 1;
	int iRes = 1;
	int ErrorNo = 0;
	QString text;
	QString picType;
	int stdHight = m_NozzleHight[1].P0;

	try {
		m_hdev->AdjustNozzleHeight(*m_ImgHigh2, *m_HighROI2, *m_OutRegionHigh2, *m_OutXldHigh2, stdHight, \
			& Height, &iResult, &iError);
		iRes = iResult.I();
		ErrorNo = iError.I();
	}
	catch (...)
	{
		m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
		DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh2);
		text = "外部图像处理调用出错！";
		picType = "外部图像处理调用出错";
		Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
		imgResult.P[0] = 999999;
		goto end;
	}

	if (ErrorNo == 0)
	{
		if (iRes == 0)//OK
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "green");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh2, m_OutRegionHigh2, m_OutXldHigh2);
			text = "目标高度2：" + QString::number(Height[1].D()) + "um   "
				"需调整2：" + QString::number(Height[0].D()) + "um";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "green");
			imgResult.P[0] = Height[0].D();
		}
	}
	else
	{
		if (ErrorNo == -1)//内部图像处理出错
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh2);
			text = "内部图像处理出错！";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			imgResult.P[0] = 999999;
		}
	}
end:
	QDateTime DateTime = QDateTime::currentDateTime();
	QString strProcessDate = DateTime.date().toString("yyyy-MM-dd");
	QString strTimeId = DateTime.toString("hhmmss");
	QString strTimeDot = DateTime.time().toString("hh:mm:ss");

	QString picName = "NozzelHight2_" + strTimeId;

	if ((!m_bSimulate || m_bSimulateSavePic) && m_bSaveOkPic)
	{
		auto SaveImagefun = [=] {
			QString folderPath = m_PictureFolderPath + "/" + strProcessDate + "/" + m_ProductType + "/高度调节2图片/" + picType;
			if (m_bSaveOriginalPicture)
			{
				Imgtfc::SaveImage(m_ImgHigh2, picName, folderPath);
			}
			else
			{
				Imgtfc::SaveImageCompression(m_ImgHigh2, picName, folderPath);
			}
		};
		gthpool->AddTask(SaveImagefun);
	}
	LOG_DEBUG(glogger, MultUtf82Mult2(QString::number(CamNo) + "号相机高度调节2处理完成"));
	return imgResult;
}

_ImgRsult ProjectDlg::ImgProcessHight1(sptr<HObject> obj, int CamNo)
{
	_ImgRsult imgResult;
	m_ImgHigh1 = obj;
	HTuple Height, iResult,  iError;
	int DispWindNo = CamNo-1;
	int iRes = 1;
	int ErrorNo=0;
	QString text;
	QString picType;
	QString strHeight[7], strResult;

	try {
		m_hdev->GetHeightResult1(*m_ImgHigh1, *m_HighROI1, *m_OutRegionHigh1, *m_OutXldHigh1, 0, \
			m_ControlPara.at(0).P0, m_ManualBC.at(0).x, &Height,&iResult, &iError);
		iRes = iResult.I();
		ErrorNo = iError.I();
	}
	catch (...)
	{
		m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
		DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1);
		text = "外部图像处理调用出错！";
		picType = "外部图像处理调用出错";
		Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
		//if(!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Error);
		imgResult.P[0] = (int)IMG_RESULT::Error;

		strHeight[0] = "Error";
		strResult = "Error";
		strHeight[4] = "Error";
		goto end;
	}

	if (ErrorNo == 0)
	{
		if (iRes == 1 && m_bShieldHight)
		{
			iRes = 0;
		}
		if (iRes == 2 && m_bShieldWarPage)
		{
			iRes = 0;
		}

		if (iRes==0)//OK
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "green");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1, m_OutRegionHigh1, m_OutXldHigh1);
			text = "厚度1：" + QString::number(Height[0].D(), 'f', 3) + "mm  OK  "
				   "翘曲1：" + QString::number(Height[4].D(), 'f', 3) + "mm  OK";

			picType = "OK产品";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "green");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::OK);
			imgResult.P[0] = (int)IMG_RESULT::OK;
			strResult = "OK";
			for (int i=0;i< Height.Length();i++)
			{
				strHeight[i] = QString::number(Height[i].D(), 'f', 3);
			}
		}
		else if (iRes == 1)//厚度NG
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1, m_OutRegionHigh1, m_OutXldHigh1);
			text = "厚度1：" + QString::number(Height[0].D(), 'f', 3) + "mm  NG  "
				   "翘曲1：" + QString::number(Height[4].D(), 'f', 3) + "mm  OK";

			picType = "厚度超出范围";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "HeightNG";
			for (int i = 0; i < 7; i++)
			{
				strHeight[i] = QString::number(Height[i].D(), 'f', 3);
			}
		}
		else if (iRes ==2)//翘曲NG
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1, m_OutRegionHigh1, m_OutXldHigh1);
			text = "厚度1：" + QString::number(Height[0].D(), 'f', 3) + "mm  OK  "
				   "翘曲1：" + QString::number(Height[4].D(), 'f', 3) + "mm  NG";

			picType = "翘曲超出范围";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "WarPageNG";
			for (int i = 0; i < 7; i++)
			{
				strHeight[i] = QString::number(Height[i].D(), 'f', 3);
			}
		}
		else if (iRes == 3)//翘曲厚度都NG
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1, m_OutRegionHigh1, m_OutXldHigh1);
			text = "厚度1：" + QString::number(Height[0].D(), 'f', 3) + "mm  NG  "
				   "翘曲1：" + QString::number(Height[4].D(), 'f', 3) + "mm  NG";

			picType = "厚度翘曲超出范围";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "HeightWarPageNG";
			for (int i = 0; i < Height.Length(); i++)
			{
				strHeight[i] = QString::number(Height[i].D(), 'f', 3);
			}
		}
	}
	else
	{
		if (ErrorNo == -1)//内部图像处理出错
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1);
			text = "内部图像处理出错！";
			picType = "内部图像处理出错";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Error);
			imgResult.P[0] = (int)IMG_RESULT::Error;
			strHeight[0] = "Error";
			strResult = "Error";
			strHeight[4] = "Error";
		}
		else if (ErrorNo == -2)//无产品
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh1);
			text = "无产品";
			picType = "无产品";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Empty);
			imgResult.P[0] = (int)IMG_RESULT::Empty;
			strResult = "Empty";
			strHeight[0] = "Empty";
			strHeight[4] = "Empty";

		}
	}
end:
	QDateTime DateTime = QDateTime::currentDateTime();
	QString strProcessDate = DateTime.date().toString("yyyy-MM-dd");
	QString strTimeId = DateTime.toString("hhmmss");
	QString strTimeDot = DateTime.time().toString("hh:mm:ss");

	QString picName = "WarPage1_" + strTimeId+"_" + strHeight[4];

	if ((!m_bSimulate || m_bSimulateSavePic) && m_bSaveOkPic)
	{
		auto SaveImagefun = [=] {
			QString folderPath = m_PictureFolderPath + "/" + strProcessDate + "/" + m_ProductType + "/翘曲度1图片/"+ picType;
			if (m_bSaveOriginalPicture)
			{
				Imgtfc::SaveImage(m_ImgHigh1, picName, folderPath);
			}
			else
			{
				Imgtfc::SaveImageCompression(m_ImgHigh1, picName, folderPath);
			}
		};
		gthpool->AddTask(SaveImagefun);
	}

	auto fun = [=] {
		QString FolderPath = m_CsvFolderPath + "/" + strProcessDate + "/" + m_ProductType;
		if (!GetmtfInstance()->isFolderExist(FolderPath))
		{
			GetmtfInstance()->CreateExteriorFolder(FolderPath);
		}
		QString filePath = FolderPath + "/翘曲度1数据"+ m_ProductType +".csv";
		if (!GetmtfInstance()->isFileExist(filePath))
		{
			WriteHighCsvHeader(filePath);
		}

		QString strResult0, strResult1, strResult2;
		if (strResult == "OK")
		{
			strResult0 = strResult;
			strResult1 = strResult;
			strResult2 = strResult; 
		}
		else if (strResult == "HeightNG")
		{
			strResult0 = "NG";
			strResult1 = "OK";
			strResult2 = "NG";
		}
		else if (strResult == "WarPageNG")
		{
			strResult0 = "OK";
			strResult1 = "NG";
			strResult2 = "NG";
		}
		else if (strResult == "HeightWarPageNG")
		{
			strResult0 = "NG";
			strResult1 = "NG";
			strResult2 = "NG";
		}
		else
		{
			strResult0 = strResult;
			strResult1 = strResult;
			strResult2 = strResult;
		}

		WriteHighCsvData(strTimeDot, strHeight[0], strResult0,
			strHeight[1], strHeight[2], strHeight[3],
			strHeight[4], strHeight[5], strHeight[6], strResult1,
			strResult2, filePath);
	};
	gthpool->AddTask(fun);
	//emit postShowData("翘曲1",true, strHeight, strResult, "");
	imgResult.str[0] = strHeight[0];
	imgResult.str[1] = strResult;
	imgResult.str[2] = strHeight[4];
	imgResult.str[3] = strHeight[5];
	imgResult.str[4] = strHeight[6];
	LOG_DEBUG(glogger, MultUtf82Mult2(QString::number(CamNo) + "号相机图像处理完成"));
	return imgResult;
}

_ImgRsult ProjectDlg::ImgProcessHight2(sptr<HObject> obj, int CamNo)
{
	_ImgRsult imgResult;
	m_ImgHigh2 = obj;
	HTuple Height, iResult, iError;
	int DispWindNo = CamNo-1;
	int iRes = 0;
	int ErrorNo = 0;
	QString text;
	QString picType;
	QString strHeight[7], strResult;

	try {
		m_hdev->GetHeightResult2(*m_ImgHigh2, *m_HighROI2, *m_OutRegionHigh2, *m_OutXldHigh2, 0, \
			m_ControlPara.at(0).P0, m_ManualBC.at(1).x, &Height, &iResult, &iError);
		iRes =iResult.I();
		ErrorNo = iError.I();
	}
	catch (...)
	{
		m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
		DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh2);
		text = "外部图像处理调用出错！";
		picType = "外部图像处理调用出错";
		Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
		//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Error);
		imgResult.P[0] = (int)IMG_RESULT::Error;
		strHeight[0] = "Error";
		strResult = "Error";
		strHeight[4] = "Error";
		goto end;
	}

	if (ErrorNo == 0)
	{
		if (iRes == 1 && m_bShieldHight)
		{
			iRes = 0;
		}

		if (iRes == 2 && m_bShieldWarPage)
		{
			iRes = 0;
		}

		if (iRes == 0)//OK
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "green");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh2, m_OutRegionHigh2, m_OutXldHigh2);
			text = "厚度2：" + QString::number(Height[0].D(), 'f', 3) + "mm  OK  "
				"翘曲2：" + QString::number(Height[4].D(), 'f', 3) + "mm  OK";

			picType = "OK产品";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "green");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::OK);
			imgResult.P[0] = (int)IMG_RESULT::OK;
			strResult = "OK";
			for (int i = 0; i < Height.Length(); i++)
			{
				strHeight[i] = QString::number(Height[i].D(), 'f', 3);
			}
		}
		else if (iRes == 1)//厚度NG
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh2, m_OutRegionHigh2, m_OutXldHigh2);
			text = "厚度2：" + QString::number(Height[0].D(), 'f', 3) + "mm  NG  "
				"翘曲2：" + QString::number(Height[4].D(), 'f', 3) + "mm  OK";

			picType = "厚度超出范围";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "HeightNG";
			for (int i = 0; i < 7; i++)
			{
				strHeight[i] = QString::number(Height[i].D(), 'f', 3);
			}
		}
		else if (iRes == 2)//翘曲NG
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh2, m_OutRegionHigh2, m_OutXldHigh2);
			text = "厚度2：" + QString::number(Height[0].D(), 'f', 3) + "mm  OK  "
				"翘曲2：" + QString::number(Height[4].D(), 'f', 3) + "mm  NG";

			picType = "翘曲超出范围";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "WarPageNG";
			for (int i = 0; i < 7; i++)
			{
				strHeight[i] = QString::number(Height[i].D(), 'f', 3);
			}
		}
		else if (iRes == 3)//翘曲厚度都NG
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh2, m_OutRegionHigh2, m_OutXldHigh2);
			text = "厚度2：" + QString::number(Height[0].D(), 'f', 3) + "mm  NG  "
				"翘曲2：" + QString::number(Height[4].D(), 'f', 3) + "mm  NG";

			picType = "厚度翘曲超出范围";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "HeightWarPageNG";
			for (int i = 0; i < Height.Length(); i++)
			{
				strHeight[i] = QString::number(Height[i].D(), 'f', 3);
			}
		}
	}
	else
	{
		if (ErrorNo == -1)//内部图像处理出错
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh2);
			text = "内部图像处理出错！";
			picType = "内部图像处理出错";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Error);
			imgResult.P[0] = (int)IMG_RESULT::Error;
			strHeight[0] = "Error";
			strResult = "Error";
			strHeight[4] = "Error";
		}
		else if (ErrorNo == -2)//无产品
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgHigh2);
			text = "无产品";
			picType = "无产品";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Empty);
			imgResult.P[0] = (int)IMG_RESULT::Empty;
			strResult = "Empty";
			strHeight[0] = "Empty";
			strHeight[4] = "Empty";
		}
	}
end:
	QDateTime DateTime = QDateTime::currentDateTime();
	QString strProcessDate = DateTime.date().toString("yyyy-MM-dd");
	QString strTimeId = DateTime.toString("hhmmss");
	QString strTimeDot = DateTime.time().toString("hh:mm:ss");

	QString picName = "WarPage2_" + strTimeId + "_" + strHeight[4];


	if ((!m_bSimulate || m_bSimulateSavePic) && m_bSaveOkPic)
	{
		auto SaveImagefun = [=] {
			QString folderPath = m_PictureFolderPath + "/" + strProcessDate + "/" + m_ProductType + "/翘曲度2图片/" + picType;
			if (m_bSaveOriginalPicture)
			{
				Imgtfc::SaveImage(m_ImgHigh2, picName, folderPath);
			}
			else
			{
				Imgtfc::SaveImageCompression(m_ImgHigh2, picName, folderPath);
			}
		};
		gthpool->AddTask(SaveImagefun);
	}

	auto fun = [=] {
		QString FolderPath = m_CsvFolderPath + "/" + strProcessDate + "/" + m_ProductType;
		if (!GetmtfInstance()->isFolderExist(FolderPath))
		{
			GetmtfInstance()->CreateExteriorFolder(FolderPath);
		}
		QString filePath = FolderPath + "/翘曲度2数据" + m_ProductType + ".csv";
		if (!GetmtfInstance()->isFileExist(filePath))
		{
			WriteHighCsvHeader(filePath);
		}
		QString strResult0, strResult1, strResult2;
		if (strResult == "OK")
		{
			strResult0 = strResult;
			strResult1 = strResult;
			strResult2 = strResult;
		}
		else if (strResult == "HeightNG")
		{
			strResult0 = "NG";
			strResult1 = "OK";
			strResult2 = "NG";
		}
		else if (strResult == "WarPageNG")
		{
			strResult0 = "OK";
			strResult1 = "NG";
			strResult2 = "NG";
		}
		else if (strResult == "HeightWarPageNG")
		{
			strResult0 = "NG";
			strResult1 = "NG";
			strResult2 = "NG";
		}
		else
		{
			strResult0 = strResult;
			strResult1 = strResult;
			strResult2 = strResult;
		}

		WriteHighCsvData(strTimeDot, strHeight[0], strResult0,
			strHeight[1], strHeight[2], strHeight[3],
			strHeight[4], strHeight[5], strHeight[6], strResult1,
			strResult2, filePath);
	};
	gthpool->AddTask(fun);
	//emit postShowData("翘曲2", false, strHeight, strResult, "");
	LOG_DEBUG(glogger, MultUtf82Mult2(QString::number(CamNo)+"号相机图像处理完成"));
	imgResult.str[0] = strHeight[0];
	imgResult.str[1] = strResult;
	imgResult.str[2] = strHeight[4];
	imgResult.str[3] = strHeight[5];
	imgResult.str[4] = strHeight[6];
	return imgResult;
}

_ImgRsult ProjectDlg::ImgProcessFront(sptr<HObject> obj, int CamNo)
{
	_ImgRsult imgResult;
	m_ImgFront = obj;
	HTuple EdgeGray, EdgeLen, EdgeW, EdgeArea;
	HTuple FrontGray, FrontLen, FrontW, FrontArea;
	HTuple  iResult, iError;
	HTuple strDLResult, BboxRow, BboxCol;

	int DispWindNo = CamNo - 1;
	bool isOk = false;
	int ErrorNo = 0;
	QString text;
	QString picType;
	QString strResult;

	EdgeGray = m_Gray[0];
	EdgeLen = m_Len[0];
	EdgeW = m_Width[0];
	EdgeArea = m_Area[0];
	FrontGray = m_Gray[1];
	FrontLen = m_Len[1];
	FrontW = m_Width[1];
	FrontArea= m_Area[1];

	try {
		m_hdev->GetAppearanceResult(*m_ImgFront, *m_FrontROI, *m_OutRegionFront, *m_OutXldFrontROI,\
			m_ControlPara.at(1).P0, 
			EdgeGray, EdgeLen, EdgeW, EdgeArea,
			FrontGray, FrontLen, FrontW, FrontArea, m_DeformationModelID,
			m_DLModelHandle, m_DLPreprocessParam, m_ClassNames, m_ClassIDs,
			&iResult, &iError, &strDLResult, &BboxRow, &BboxCol);

		isOk = (bool)iResult.I();
		ErrorNo = iError.I();
	}
	catch (...)
	{
		m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
		DlgDispImg(m_pwnd[DispWindNo], "", m_ImgFront);
		text = "外部图像处理调用出错！";
		picType = "外部图像处理调用出错";
		Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
		//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Error);
		imgResult.P[0] = (int)IMG_RESULT::Error;
		strResult = "N/A";
		goto end;
	}

	if (ErrorNo == 0 || m_bShieldAppearance)
	{
		if (isOk || m_bShieldAppearance)//OK
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "green");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgFront, m_OutXldFrontROI, m_OutRegionFront);
			text = "外观： OK";
			picType = "外观OK";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "green");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::OK);
			imgResult.P[0] = (int)IMG_RESULT::OK;
			strResult = "OK";
		}
		else //NG
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgFront, m_OutXldFrontROI,m_OutRegionFront);
	
			QString qstrDLResult = strDLResult.S().ToUtf8();
			if (qstrDLResult != "")
			{
				int len = strDLResult.Length();
				for (int i=0;i<len;i++)
				{
					SetTposition(m_pwnd[DispWindNo]->m_hHalconID, BboxRow[i], BboxCol[i]);
					WriteString(m_pwnd[DispWindNo]->m_hHalconID, strDLResult[i]);
				}
			}
			text = "外观： NG";
			picType = "外观NG";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "NG";
		}
	}
	else
	{
		if (ErrorNo == -1)//内部图像处理出错
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgFront);
			text = "内部图像处理出错！";
			picType = "内部图像处理出错";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Error);
			imgResult.P[0] = (int)IMG_RESULT::Error;
			strResult = "Error";
		}
		else if (ErrorNo == -2)//无产品
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgFront);
			text = "无产品";
			picType = "无产品";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Empty);
			imgResult.P[0] = (int)IMG_RESULT::Empty;
			strResult = "Empty";
		}
		else if (ErrorNo == -3)//有产品，位置异常
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgFront);
			text = "有产品，位置异常";
			picType = "位置异常";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Empty);
			imgResult.P[0] = (int)IMG_RESULT::BadPos;
			strResult = "BadPos";
		}
		else if (ErrorNo == -4)//InferDetection Error
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgFront);
			text = "InferError";
			picType = "InferError";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Empty);
			imgResult.P[0] = (int)IMG_RESULT::InferError;
			strResult = "InferError";
		}
	}
end:
	QDateTime DateTime = QDateTime::currentDateTime();
	QString strProcessDate = DateTime.date().toString("yyyy-MM-dd");
	QString strTimeId = DateTime.toString("hhmmss");
	QString strTimeDot = DateTime.time().toString("hh:mm:ss");

	QString picName = "外观_" + strTimeId;

	if ((!m_bSimulate || m_bSimulateSavePic) && m_bSaveOkPic)
	{
		auto SaveImagefun = [=] {
			QString folderPath = m_PictureFolderPath + "/" + strProcessDate + "/" + m_ProductType + "/外观图片/" + picType;
			if (m_bSaveOriginalPicture)
			{
				Imgtfc::SaveImage(m_ImgFront, picName, folderPath);
			}
			else
			{
				Imgtfc::SaveImageCompression(m_ImgFront, picName, folderPath);
			}
		};
		gthpool->AddTask(SaveImagefun);
	}

	auto fun = [=] {
		QString FolderPath = m_CsvFolderPath + "/" + strProcessDate + "/" + m_ProductType;
		if (!GetmtfInstance()->isFolderExist(FolderPath))
		{
			GetmtfInstance()->CreateExteriorFolder(FolderPath);
		}
		QString filePath = FolderPath + "/外观检测数据" + m_ProductType + ".csv";
		if (!GetmtfInstance()->isFileExist(filePath))
		{
			WriteAppearenceCsvHeader(filePath);
		}
		WriteAppearenceCsvData(strTimeDot,strResult, filePath);
	};
	gthpool->AddTask(fun);

	LOG_DEBUG(glogger, MultUtf82Mult2(QString::number(CamNo) + "号相机图像处理完成"));

	imgResult.str[0] = strResult;
	return imgResult;
}

_ImgRsult ProjectDlg::ImgProcessDeformation(sptr<HObject> obj,int CamNo)
{
	_ImgRsult imgResult;
	m_ImgDeformation = obj;
	HTuple iResult, iError;
	int DispWindNo = CamNo - 1;
	QString strResultType;
	int ErrorNo = 0;
	QString text;
	QString text2;
	QString picType;
	QString  strResult;

	HTuple RefX, RefY, RefR;
	HTuple R,Width;

	RefX = m_RoiRefPoint.at(0);
	RefY= m_RoiRefPoint.at(1);
	RefR= m_RoiRefPoint.at(2);

	double Width1=0, Width2 = 0, Width3 = 0, Width4 = 0;
	double R1 = 0,R2 = 0, R3 = 0, R4 = 0;

	try {
		m_hdev->GetShapeResult(*m_ImgDeformation, *m_DeformationROI, *m_OutRegionDeformation, *m_OutXldDeformation,
			m_DeformationModelID, m_ControlPara.at(2).P0,
			RefX, RefY, RefR,	
			m_ShapeParaBC.at(0).P0, m_ShapeParaBC.at(0).P1, m_ShapeParaBC.at(0).P2, m_ShapeParaBC.at(0).P3,
			m_ShapeParaBC.at(0).P4, m_ShapeParaBC.at(0).P5, m_ShapeParaBC.at(0).P6, m_ShapeParaBC.at(0).P7,
			&iResult, &iError,&R, &Width);

		strResultType = iResult.S().TextA();
		ErrorNo = iError.I();
	}
	catch (...)
	{
		m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
		DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation);
		text = "外部图像处理调用出错！";
		picType = "外部图像处理调用出错";
		Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
		//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Error);
		imgResult.P[0] = (int)IMG_RESULT::Error;
		strResult = "N/A";
		goto end;
	}

	if (ErrorNo == 0 || m_bShieldDeformation)
	{
		if (!m_bShieldDeformation)
		{
			Width1 = Width[0].D();
			Width2 = Width[1].D();
			Width3 = Width[2].D();
			Width4 = Width[3].D();

			R1 = R[0].D();
			R2 = R[1].D();
			R3 = R[2].D();
			R4 = R[3].D();
		}
		text = "环宽度：" + QString::number(Width1) + "mm,"
			+ QString::number(Width2) + "mm,"
			+ QString::number(Width3) + "mm,"
			+ QString::number(Width4) + "mm  ";
		text2 = "环角度：" + QString::number(R1) + "°,"
			+ QString::number(R2) + "°,"
			+ QString::number(R3) + "°,"
			+ QString::number(R4) + "°  ";

		if (strResultType == "OK" || m_bShieldDeformation)//OK
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "green");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation, m_OutRegionDeformation, m_OutXldDeformation);
			picType = "OK产品";

			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text+"OK", "green");
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row2, (int)TL::Colm, text2 + "OK", "green");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::OK);
			imgResult.P[0] = (int)IMG_RESULT::OK;
			strResult = "OK";
		}
		else if(strResultType == "OutOfWidth")//NG
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation, m_OutRegionDeformation, m_OutXldDeformation);
			picType = "环宽度超范围";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text + "NG", "red");
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row2, (int)TL::Colm, text2 + "OK", "green");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "环宽度超范围";
		}
		else if (strResultType == "OutOfAngel")//NG
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation, m_OutRegionDeformation, m_OutXldDeformation);
			picType = "角度超范围";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text + "OK", "green");
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row2, (int)TL::Colm, text2 + "NG", "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "角度超范围";
		}
		else if (strResultType == "OutOfWidth&Angel")//NG
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation, m_OutRegionDeformation, m_OutXldDeformation);
			picType = "宽度和角度均超范围";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text + "NG", "red");
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row2, (int)TL::Colm, text2 + "NG", "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "宽度和角度均超范围";
		}
	}
	else
	{
		if (ErrorNo == -1)//内部图像处理出错
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation);
			text = "图像处理出错！";
			picType = "图像处理出错";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text + "  NG", "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Error);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "Error";
		}
		else if (ErrorNo == -2)//无产品
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation);
			text = "无产品";
			picType = "无产品";
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text + "  NG", "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::Empty);
			imgResult.P[0] = (int)IMG_RESULT::Empty;
			strResult = "Empty";
		}
		else if (ErrorNo == -3)//宽度异常
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation);
			text = "严重变形产品";
			picType = "严重变形";
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation, m_OutRegionDeformation, m_OutXldDeformation);
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text + "  NG", "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "Deformation";
		}
		else if (ErrorNo == -4)//角度异常
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation);
			text = "严重变形产品";
			picType = "严重变形";
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation, m_OutRegionDeformation, m_OutXldDeformation);
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text + "  NG", "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "Deformation";
		}
		else if (ErrorNo == -5)//宽度和角度均异常
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation);
			text = "严重变形产品";
			picType = "宽和角度严重变形";
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation, m_OutRegionDeformation, m_OutXldDeformation);
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text + "  NG", "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::NG;
			strResult = "Deformation";
		}
		else if (ErrorNo == -6)//有产品，匹配失败
		{
			m_pwnd[DispWindNo]->SetDispStyle("margin", "red");
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation);
			text = "有产品，位置异常";
			picType = "有产品,匹配失败";
			DlgDispImg(m_pwnd[DispWindNo], "", m_ImgDeformation, m_OutRegionDeformation, m_OutXldDeformation);
			Imgtfc::dispText(m_pwnd[DispWindNo]->m_hHalconID, (int)TL::Row1, (int)TL::Colm, text, "red");
			//if (!m_bShieldComm) m_pSktLinkMaster->ProcessImageResult(CamNo, (int)IMG_RESULT::NG);
			imgResult.P[0] = (int)IMG_RESULT::BadPos;
			strResult = "BadPos";
		}
	}

end:
	QDateTime DateTime = QDateTime::currentDateTime();
	QString strProcessDate = DateTime.date().toString("yyyy-MM-dd");
	QString strTimeId = DateTime.toString("hhmmss");
	QString strTimeDot = DateTime.time().toString("hh:mm:ss");

	QString picName = "变形_" + strTimeId;

	if ((!m_bSimulate || m_bSimulateSavePic) && m_bSaveOkPic)
	{
		auto SaveImagefun = [=] {
			QString folderPath = m_PictureFolderPath + "/" + strProcessDate + "/" + m_ProductType + "/变形图片/"+ picType;
			if (m_bSaveOriginalPicture)
			{
				Imgtfc::SaveImage(m_ImgDeformation, picName, folderPath);
			}
			else
			{
				Imgtfc::SaveImageCompression(m_ImgDeformation, picName, folderPath);
			}
		};
		gthpool->AddTask(SaveImagefun);
	}

	auto fun = [=] {
		QString FolderPath = m_CsvFolderPath + "/" + strProcessDate + "/" + m_ProductType;
		if (!GetmtfInstance()->isFolderExist(FolderPath))
		{
			GetmtfInstance()->CreateExteriorFolder(FolderPath);
		}
		QString filePath = FolderPath+ "/变形检测数据" + m_ProductType + ".csv";
		if (!GetmtfInstance()->isFileExist(filePath))
		{
			WriteShapeCsvHeader(filePath);
		}
		WriteShapeCsvData(strTimeDot, strResult, Width1, Width2,Width3, Width4, R1, R2, R3, R4,filePath);
	};
	gthpool->AddTask(fun);

	LOG_DEBUG(glogger, MultUtf82Mult2(QString::number(CamNo) + "号相机图像处理完成"));
	imgResult.str[0] = strResult;
	return imgResult;
}

//==============================================================================================================================================
void ProjectDlg::DefaultPathConvert()
{
	bool ret = GetmtfInstance()->DefaultPathConvert("DataFile", m_PlcCmdPath);

	for (int i = 0; i < m_ModelFilefullPath.size(); i++)
	{
		QString temp = toqstr(m_ModelFilefullPath.at(i));
		GetmtfInstance()->DefaultPathConvert("DataFile", temp);
		m_ModelFilefullPath.at(i) = temp.tostr();
	}

	for (int i = 0; i < m_MatFilefullPath.size(); i++)
	{
		QString temp = toqstr(m_MatFilefullPath.at(i));
		GetmtfInstance()->DefaultPathConvert("DataFile", temp);
		m_MatFilefullPath.at(i) = temp.tostr();
	}
}

void ProjectDlg::LoadCalibFile()
{
	try
	{
		QString path = "DataFile/" + gProjectFolder + "/File/ROI/厚度ROI/"+ m_ProductType;
		QString file = "Roi_" + QString::number(1) +"_"+ m_ProductType + ".hobj";
		QString pathFile = GetmtfInstance()->CreateInnerFile(0, path, file);
		HTuple hvPath = pathFile.toLocal8Bit().data();
		m_HighROI1 = std::make_shared<HObject>();
		ReadObject(m_HighROI1.get(), hvPath);//ReadObject
	}
	catch (...)
	{
		LOG_DEBUG(glogger, MultUtf82Mult2("加载厚度1ROI出错！"));
		MessageBoxTip("加载厚度1ROI出错！");
	}

	try
	{
		QString path = "DataFile/" + gProjectFolder+ "/File/ROI/厚度ROI/" + m_ProductType;
		QString file = "Roi_" + QString::number(2) + "_" + m_ProductType + ".hobj";
		QString pathFile = GetmtfInstance()->CreateInnerFile(0, path, file);
		HTuple hvPath = pathFile.toLocal8Bit().data();
		m_HighROI2 = std::make_shared<HObject>();
		ReadObject(m_HighROI2.get(), hvPath);//ReadObject
	}
	catch (...)
	{
		LOG_DEBUG(glogger, MultUtf82Mult2("加载厚度2ROI出错！"));
		MessageBoxTip("加载厚度2ROI出错！");
	}

	try
	{
		HalconCpp::SetHcppInterfaceStringEncodingIsUtf8(false);//
		QString path = "DataFile/" + gProjectFolder + "/File/ROI/正面外观ROI/" + m_ProductType;
		QString file = "正面外观ROI_"+ m_ProductType +".hobj";
		QString pathFile = GetmtfInstance()->CreateInnerFile(0, path, file);
		HTuple hvPath = pathFile.toLocal8Bit().data();
		ReadObject(m_FrontROI.get(), hvPath);//ReadObject

	}
	catch (...)
	{
		LOG_DEBUG(glogger, MultUtf82Mult2("加载正面外观ROI出错！"));
		MessageBoxTip("加载正面外观ROI出错！");
	}

	try
	{
		sptr<HObject> Roi[4];
		for (int i = 0; i < 4; i++)
		{
			QString path = "DataFile/" + gProjectFolder +"/File/ROI/变形ROI/" + m_ProductType;
			QString file = "Roi_" + QString::number(i + 1) + "_" + m_ProductType + ".hobj";
			QString pathFile = GetmtfInstance()->CreateInnerFile(0, path, file);
			if(i==0) m_RoiRefPoint = ReadRefPoint(pathFile);
			HTuple hvPath = pathFile.toLocal8Bit().data();
			Roi[i] = std::make_shared<HObject>();
			ReadObject(Roi[i].get(), hvPath);//ReadObject
		}
		m_DeformationROI = mksptr<HObject>();//变形 4ROI
		GenEmptyObj(m_DeformationROI.get());// Create an empty object tuple.

		*m_DeformationROI = *Roi[0];//第一个手动复制
		for (int i =1; i < 4; i++)
		{
			ConcatObj(*m_DeformationROI, *Roi[i], m_DeformationROI.get());//变形 
		}
		int num = m_DeformationROI->CountObj();
	}
	catch (...)
	{
		LOG_DEBUG(glogger, MultUtf82Mult2("加载变形ROI出错！"));
		MessageBoxTip("加载变形ROI出错！");
	}

	try
	{
		QString path = "DataFile/"+gProjectFolder+"/File/CameraCalibFile";
		QString file = "CalibDataID.ccd";
		QString pathFile = GetmtfInstance()->CreateInnerFile(0, path, file);
		HTuple path2 = pathFile.toLocal8Bit().data();
		ReadCalibData(path2, &m_CalibDataID);

		file = "CameraPara.cal";
		pathFile = GetmtfInstance()->CreateInnerFile(0, path, file);
		path2 = pathFile.toLocal8Bit().data();
		::ReadCamPar(path2, &m_CameraInnerPara);

		file = "CameraPose.dat";
		pathFile = GetmtfInstance()->CreateInnerFile(0, path, file);
		path2 = pathFile.toLocal8Bit().data();
		::ReadPose(path2, &m_CameraPose);
	}
	catch (...)
	{
		LOG_DEBUG(glogger, MultUtf82Mult2("加载相机标定文件出错！"));
		MessageBoxTip("加载相机标定文件出错！");
	}

	try
	{
		QString path = "DataFile/"+gProjectFolder + "/File/Model/变形检测定位模板/" + m_ProductType;
		QString file = "变形检测定位模板"+m_ProductType+".shm";
		QString pathFile = GetmtfInstance()->CreateInnerFile(0, path, file);
		HTuple path2 = pathFile.toLocal8Bit().data();
		ReadShapeModel(path2, &m_DeformationModelID);
	}
	catch (...)
	{
		LOG_DEBUG(glogger, MultUtf82Mult2("变形检测定位模板句柄加载出错！"));
		MessageBoxTip("变形检测定位模板句柄加载出错！");
	}

	//try
	//{
	//	HTuple iError = 0;
	//	HTuple DLModelHandle, DLPreprocessParam, ClassNames, ClassIDs;
	//    m_hdev->InitInferDetection(&DLModelHandle, &DLPreprocessParam, &ClassNames, &ClassIDs, &iError);
	//	if (iError!=0)
	//	{
	//		LOG_DEBUG(glogger, MultUtf82Mult2("加载深度学习模型句柄出错！"));
	//		MessageBoxTip("加载深度学习模型句柄出错！");
	//		return;
	//	}
	//	m_DLModelHandle = DLModelHandle;
	//	m_DLPreprocessParam = DLPreprocessParam;
	//	m_ClassNames = ClassNames;
	//	m_ClassIDs = ClassIDs;
	//}
	//catch (...)
	//{
	//	LOG_DEBUG(glogger, MultUtf82Mult2("加载深度学习模型句柄出错！"));
	//	MessageBoxTip("加载深度学习模型句柄出错！");
	//}

}

void ProjectDlg::DispVersion_cb(QStatusBar* pStatusBar, QLabel& label)
{
	label.setStyleSheet(" color: white;  font: 12pt '楷书'; ");
	pStatusBar->setStyleSheet("background: brown; ");
	pStatusBar->addPermanentWidget(&label);
	label.setText(m_Version);
}

void ProjectDlg::CameraLinkState_cb(int camNum, bool isLinked)
{
	switch (camNum)
	{
	case 1:
		if (isLinked) 	m_pDispInfoDlg->LightStatus(m_pDispInfoDlg->m_pBtnStateCam_1, 1);
		else m_pDispInfoDlg->LightStatus(m_pDispInfoDlg->m_pBtnStateCam_1, 0);
		break;
	case 2:
		if (isLinked) 	m_pDispInfoDlg->LightStatus(m_pDispInfoDlg->m_pBtnStateCam_2, 1);
		else m_pDispInfoDlg->LightStatus(m_pDispInfoDlg->m_pBtnStateCam_2, 0);
		break;
	case 3:
		if (isLinked) 	m_pDispInfoDlg->LightStatus(m_pDispInfoDlg->m_pBtnStateCam_3, 1);
		else m_pDispInfoDlg->LightStatus(m_pDispInfoDlg->m_pBtnStateCam_3, 0);
		break;
	case 4:
		if (isLinked) 	m_pDispInfoDlg->LightStatus(m_pDispInfoDlg->m_pBtnStateCam_4, 1);
		else m_pDispInfoDlg->LightStatus(m_pDispInfoDlg->m_pBtnStateCam_4, 0);
		break;
	default:
		break;
	}
}

void ProjectDlg::OnDataInteraction_cb()
{
	if (g_pMesDlg != nullptr)
	{
		g_pMesDlg->show();
	}
}

void ProjectDlg::OnNotEnoughThreadEventHandle_cb(ThreadPool* pThreadPool, void* user)
{
	if (pThreadPool->GetALLThreadsNumber()>=30)
	{
		LOG_DEBUG(glogger, MultUtf82Mult2("线程数已达上限：") << 30);
	} 
	else
	{
		int thNum = pThreadPool->AddThreads(1);
		LOG_DEBUG(glogger, MultUtf82Mult2("线程增加1个,总线程数：") << thNum);
	}
}

int ProjectDlg::WriteRotateCenter2DB_cb(QString location, int number, double* CenterX, double* CenterY, double* offsetX, double* offsetY, double* offsetR, void* pBackup)
{
	if (location != "下相机") return -1;
	if (number > 6) {
		MessageBoxTip("超出下相机旋转中心数量！");
		return -1;
	}
	QString strTip = "是否更改" + location + QString::number(number) + "号吸嘴的旋转中心？";
	auto res = QMessageBox::StandardButton::NoButton;
	res = QMessageBox::information(0, "提示", strTip, QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::No);
	if(res== QMessageBox::StandardButton::No)return -1;
	GetmtfInstance()->UpdateValuesRow("conn1", "旋转中心",
	"X坐标=" + QString::number(*CenterX) + "," + "Y坐标=" + QString::number(*CenterY), "rowid="+QString::number(number+6));
	m_pThis->UpdataTable_RotateCenter();
	return 0;
}

int ProjectDlg::WriteStdPos2DB_cb(QString* location, int* number, double* X, double* Y, double* R, void* pCtrl, void* pBackup)
{
	if (*location == "放料标准位置") {
		if (*number > 30) {
			MessageBoxTip("超出标准位置数量！");
			return -1;
		}
		QString strTip = "是否更改"+ QString::number(*number) + "号" + location+"图像坐标?";
		auto res = QMessageBox::StandardButton::NoButton;
		res = QMessageBox::information(0, "提示", strTip, QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::No);
		if (res == QMessageBox::StandardButton::No)return -1;
		GetmtfInstance()->UpdateValuesRow("conn1", "放料标准图像位置",
			"图像坐标X=" + QString::number(m_pThis->m_stdDutX) + "," + "图像坐标Y=" + QString::number(m_pThis->m_stdDutY) + "," + "角度R=" + QString::number(m_pThis->m_stdDutR),
			"rowid=" + QString::number(*number));
		m_pThis->UpdataTable_StandImgPos();
	}	
	else if (*location == "载具穴位坐标") 
	{
		if (*number > 24) {
			MessageBoxTip("超出载具穴位数量！");
			return -1;
		}
		QString strTip = "是否更改" + QString::number(*number) + "号穴位图像坐标?";
		auto res = QMessageBox::StandardButton::NoButton;
		res = QMessageBox::information(0, "提示", strTip, QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::No);
		if (res == QMessageBox::StandardButton::No)return -1;

		GetmtfInstance()->UpdateValuesRow("conn1", "穴位图像坐标表",
			"坐标X=" + QString::number(m_pThis->m_stdDutX) + "," + "坐标Y=" + QString::number(m_pThis->m_stdDutY) + "," + "坐标R=" + QString::number(m_pThis->m_stdDutR),
			"序号=" + QString::number(*number));
		//m_pThis->UpdataTable_SlotImgPos();
	}
	//else if (*location == "防呆标准距离获取")
	//{

	//	QString strTip = "是否更改防呆标准距离参数?";
	//	auto res = QMessageBox::StandardButton::NoButton;
	//	res = QMessageBox::information(0, "提示", strTip, QMessageBox::StandardButton::Ok | QMessageBox::StandardButton::No);
	//	if (res == QMessageBox::StandardButton::No)return -1;
	//
	//	for (int i=0;i<24;i++)
	//	{
	//		m_pThis->m_AppearencePara.at(i).Gray = m_pThis->m_DutSlotX[i];
	//		GetmtfInstance()->UpdateSingleValue("conn1", "外观检测参数", "StdX",QString::number(m_pThis->m_DutSlotX[i]), "rowid", QString::number(i + 1));


	//		m_pThis->m_AppearencePara.at(i).Len = m_pThis->m_DutSlotY[i];
	//		GetmtfInstance()->UpdateSingleValue("conn1", "外观检测参数", "StdY", QString::number(m_pThis->m_DutSlotY[i]), "rowid", QString::number(i + 1));


	//		m_pThis->m_AppearencePara.at(i).Width = m_pThis->m_DutSlotR1[i];
	//		GetmtfInstance()->UpdateSingleValue("conn1", "外观检测参数", "StdR1", QString::number(m_pThis->m_DutSlotR1[i]), "rowid", QString::number(i + 1));
	//	
	//		m_pThis->m_AppearencePara.at(i).Width = m_pThis->m_DutSlotR2[i];
	//		GetmtfInstance()->UpdateSingleValue("conn1", "外观检测参数", "StdR2", QString::number(m_pThis->m_DutSlotR2[i]), "rowid", QString::number(i + 1));
	//	}

	//	m_pThis->UpdataTable_AppearencePara();
	//}

	return 0;
}

void ProjectDlg::DispOEEInfo_cb(QTabWidget* tabWidget)
{
	m_pProjectDB = mksptr<DataBase>();
	//m_pWorkRateDlg = new QWorkRateDlg();
	//tabWidget->addTab(m_pWorkRateDlg, "设备状态信息");
}

void ProjectDlg::TriggerCallBackFunCamera1(sptr<HObject> RtImage, void* pUser)
{
	m_CameraImg[0] = RtImage;
	m_bCameraTriggred[0] = true;
	LOG_DEBUG(glogger, MultUtf82Mult2("====>>1号相机触发完成！"));
	gthpool->AddTask(std::bind(&ProjectDlg::ImgProcess1, m_pThis, "1"));
	return;
}

void ProjectDlg::TriggerCallBackFunCamera2(sptr<HObject> RtImage, void* pUser)
{
	if(m_bAdjustNozzleModel) return;
	m_CameraImg[1] = RtImage;
	m_bCameraTriggred[1] = true;
	LOG_DEBUG(glogger, MultUtf82Mult2("====>>2号相机触发完成！"));
	gthpool->AddTask(std::bind(&ProjectDlg::ImgProcess2, m_pThis,"2"));
	return;
}

void ProjectDlg::TriggerCallBackFunCamera3(sptr<HObject> RtImage, void* pUser)
{
	m_CameraImg[2] = RtImage;
	m_bCameraTriggred[2] = true;
	LOG_DEBUG(glogger, MultUtf82Mult2("====>>3号相机触发完成！"));
	gthpool->AddTask(std::bind(&ProjectDlg::ImgProcess3, m_pThis, "3"));
	return;
}

void ProjectDlg::TriggerCallBackFunCamera4(sptr<HObject> RtImage, void* pUser)
{
	if (m_bAdjustNozzleModel) return;
	m_CameraImg[3] = RtImage;
	m_bCameraTriggred[3] = true;
	LOG_DEBUG(glogger, MultUtf82Mult2("====>>4号相机触发完成！"));
	gthpool->AddTask(std::bind(&ProjectDlg::ImgProcess4, m_pThis, "4"));
	return;
}

void ProjectDlg::timerEvent(QTimerEvent* event)
{
	//if ((event->timerId() == m_TimerId_heart) && m_pSktLinkMaster->m_bCheckHeartBeat)
	//{
	//	m_pSktLinkMaster->HeartBeat();
	//}
}

void ProjectDlg::WriteHighCsvHeader(QString filePath)
{
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << QString("检测时间").tostr() << ',' 
		<< QString("厚度mm").tostr() << ',' 
		<< QString("厚度结果").tostr() << ','
		<< QString("1点").tostr() << ','
		<< QString("2点").tostr() << ','
		<< QString("3点").tostr() << ','
		<< QString("翘曲(1-2)").tostr() << ','
		<< QString("翘曲(1-3)").tostr() << ','
		<< QString("翘曲(2-3)").tostr() << ','
		<< QString("翘曲结果").tostr() << ','
		<< QString("结果").tostr() << ','
		<< std::endl;
	outFile.close();
	CleanUpRubbishDocuments();
}

void ProjectDlg::WriteHighCsvData(QString time, QString High0, QString Result0,
	QString High1, QString High2, QString High3,
	QString High4, QString High5, QString High6,
	QString Result1,
	QString Result2, QString filePath)
{
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << time.tostr() << ','
		<< High0.tostr() << ','
		<< Result0.tostr() << ','
		<< High1.tostr() << ','
		<< High2.tostr() << ','
		<< High3.tostr() << ','
		<< High4.tostr() << ','
		<< High5.tostr() << ','
		<< High6.tostr() << ','
		<< Result1.tostr() << ','
		<< Result2.tostr() << ','
		<< std::endl;
	outFile.close();
}

void ProjectDlg::WriteAppearenceCsvHeader(QString filePath)
{
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << QString("检测时间").tostr() << ',' 
		    << QString("结果").tostr() << ','
		    << std::endl;
	outFile.close();
}

void ProjectDlg::WriteAppearenceCsvData(QString time, QString Result, QString filePath)
{
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << time.tostr() << ','
		    << Result.tostr() << ','
		    << std::endl;
	outFile.close();
}

int ProjectDlg::ReadCheckSnCsvData(QString filePath, std::map<QString,int>& SnDataMap)
{
	std::ifstream inFile(filePath.tostr(), std::ios::in);
	if (!inFile.is_open())
	{
		MessageBoxTip("点检数据加载失败！");
		return -2;
	}
	std::string lineStr;

	while (std::getline(inFile, lineStr))
	{
		std::stringstream ssline(lineStr);
		std::string str;
		for (int col = 0; std::getline(ssline, str, ';'); col++)
		{
			SnDataMap[toqstr(str)]= col;
		}
	}
	inFile.close();
	return 0;
}

void ProjectDlg::WriteShapeCsvHeader(QString filePath)
{
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << QString("检测时间").tostr() << ','
		<< QString("结果").tostr() << ','
		<< QString("Width1").tostr() << ','
		<< QString("Width2").tostr() << ','
		<< QString("Width3").tostr() << ','
		<< QString("Width4").tostr() << ','
		<< QString("R1").tostr() << ','
		<< QString("R2").tostr() << ','
		<< QString("R3").tostr() << ','
		<< QString("R4").tostr() << ','
		<< std::endl;
	outFile.close();
}

void ProjectDlg::WriteShapeCsvData(QString time, QString Result,
	double Width1,double Width2, double Width3, double Width4,
	double R1, double R2, double R3, double R4, 
	QString filePath)
{
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << time.tostr() << ','
		<< MultUtf82Mult(Result) << ','
		<< Width1 << ','
		<< Width2 << ','
		<< Width3 << ','
		<< Width4 << ','
		<< R1 << ','
		<< R2 << ','
		<< R3 << ','
		<< R4 << ','
		<< std::endl;
	outFile.close();
}

void ProjectDlg::WriteImgResultCsvHeader(QString filePath)
{
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << QString("检测时间").tostr() << ','
		//<< QString("计数").tostr() << ','
		<< QString("厚度1").tostr() << ','
		<< QString("厚度1结果").tostr() << ','
		<< QString("翘曲11").tostr() << ','
		<< QString("翘曲12").tostr() << ','
		<< QString("翘曲13").tostr() << ','
		<< QString("翘曲1结果").tostr() << ','
		<< QString("外观").tostr() << ','
		<< QString("厚度2").tostr() << ','
		<< QString("厚度2结果").tostr() << ','
		<< QString("翘曲21").tostr() << ','
		<< QString("翘曲22").tostr() << ','
		<< QString("翘曲23").tostr() << ','
		<< QString("翘曲2结果").tostr() << ','
		<< QString("变形").tostr() << ','
		<< QString("结果").tostr() << ','
		<< std::endl;
	outFile.close();
}

void ProjectDlg::WriteImgResultCsvData(QString time,/* QString count,*/
	QString Hight1, QString ImgResult1, QString Hight11, QString Hight12, QString Hight13, QString ImgResult10,
	QString appearance,
	QString Hight2, QString ImgResult2, QString Hight21, QString Hight22, QString Hight23, QString ImgResult20,
	QString distortion, QString ImgResult,
	QString filePath)
{
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << time.tostr() << ','
		<< MultUtf82Mult(Hight1) << ','
		<< MultUtf82Mult(ImgResult1) << ','
		<< MultUtf82Mult(Hight11) << ','
		<< MultUtf82Mult(Hight12) << ','
		<< MultUtf82Mult(Hight13) << ','
		<< MultUtf82Mult(ImgResult10) << ','
		<< MultUtf82Mult(appearance) << ','
		<< MultUtf82Mult(Hight2) << ','
		<< MultUtf82Mult(ImgResult2) << ','
		<< MultUtf82Mult(Hight21) << ','
		<< MultUtf82Mult(Hight22) << ','
		<< MultUtf82Mult(Hight23) << ','
		<< MultUtf82Mult(ImgResult20) << ','
		<< MultUtf82Mult(distortion) << ','
		<< MultUtf82Mult(ImgResult) << ','
		<< std::endl;
	outFile.close();
}

void ProjectDlg::WritePLCWarningCsvHeader(QString filePath)
{
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << QString("报警时间").tostr() << ',' << QString("报警编号").tostr() << ',' << QString("报警内容").tostr() << ',' << endl;
	outFile.close();
}

void ProjectDlg::WritePLCWarningCsvData(QString time, int WarningNo, QString Content, QString filePath)
{
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << time.tostr() << ','<< WarningNo << ',' << Content.tostr() << ',' << endl;
	outFile.close();
}

void ProjectDlg::WriteWorkRateCsvHeader()
{
	QDateTime DataTime = QDateTime::currentDateTime();
	QString strData = DataTime.date().toString("yyyy-MM-dd");
	QString filePath = m_WorkRateFolderPath + "/" + GetSetTableName() + ".csv";
	if (GetmtfInstance()->isFileExist(filePath)) return;

	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << QString("时间").tostr() << ',' 
		<< QString("总时长").tostr() << ','

		<< QString("生产时间/H").tostr() << ','
		<< QString("待料时间/H").tostr() << ','
		<< QString("报警时间/H").tostr() << ','
		<< QString("故障时间/H").tostr() << ','
		<< QString("产量/H").tostr() << ','

		<< QString("稼动率/H").tostr() << ','
		<< QString("待料率/H").tostr() << ','
		<< QString("故障率/H").tostr() << ','

		<< QString("总生产时间").tostr() << ','
		<< QString("总待料时间").tostr() << ','
		<< QString("总报警时间").tostr() << ','
		<< QString("总故障时间").tostr() << ','
		<< QString("总产量").tostr() << ','

		<< QString("总稼动率").tostr() << ','
		<< QString("总待机率").tostr() << ','
		<< QString("总故障率").tostr() << ','

		<< QString("定位失败/H").tostr() << ','
		<< QString("总定位失败").tostr() << ','

		<< endl;
	outFile.close();
}

void ProjectDlg::WriteWorkRateCsvData(INT64 totalTime,
	INT64 workTime, INT64 waitTime, INT64 WarningTime, INT64 faultTime, int outPut,
	double workRate, double waitRate, double faultRate,
	INT64 totalWorkTime, INT64 totalWaitTime, INT64 totalWarningTime, INT64 totalFaultTime, int totalOutPut,
	double totalWorkRate, double totalWaitRate, double totalFaultRate,
	int curPositingFail, int  TotalPositingFail
	)
{
	QDateTime DataTime = QDateTime::currentDateTime();
	QString strData = DataTime.date().toString("yyyy-MM-dd");
	QString strTimeDot = DataTime.time().toString("hh:mm:ss");

	QString filePath = m_WorkRateFolderPath + "/" + GetSetTableName() + ".csv";
	if (!GetmtfInstance()->isFileExist(filePath))
	{
		WriteWorkRateCsvHeader();
	}
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << strTimeDot.tostr() << ','  << totalTime << ','
		    << workTime << ',' << waitTime << ',' << WarningTime << ',' << faultTime << ','<< outPut<<","
		    << Round_off(workRate, 3) << ',' << Round_off(waitRate, 3) << ',' << Round_off(faultRate, 3) << ','
		    << totalWorkTime << ',' << totalWaitTime << ',' << totalWarningTime << ',' << totalFaultTime << ',' << totalOutPut << ","
		    << Round_off(totalWorkRate, 3) << ',' << Round_off(totalWaitRate, 3) << ',' << Round_off(totalFaultRate, 3) << ','
		    << curPositingFail << ',' << TotalPositingFail << ","
		    << endl;
	outFile.close();
}


void ProjectDlg::WriteBindDutSlotCsvHeader(QString filePath)
{
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << QString("时间").tostr() << ','
		<< QString("二维码").tostr() << ','
		<< QString("穴位").tostr() << ','
		<< QString("状态").tostr() << ','
		<< QString("载具ID").tostr() << ','
		<< QString("测量X").tostr() << ','
		<< QString("测量Y").tostr() << ','
		<< QString("动态产品R1").tostr() << ','
		<< QString("动态穴位R2").tostr() << ','
		<< QString("标准X").tostr() << ','
		<< QString("标准Y").tostr() << ','
		<< QString("标准产品R1").tostr() << ','
		<< QString("标准穴位R2").tostr() << ','
		<< QString("差值X").tostr() << ','
		<< QString("差值Y").tostr() << ','
		<< QString("动态产品R1-标准产品R1").tostr() << ','
		<< QString("动态产品R1-标准穴位R2").tostr() << ','
		<< QString("动态产品R1-动态穴位R2").tostr() << ','
		<< std::endl;
	outFile.close();
}

void ProjectDlg::WriteBindDutSlotCsvData(QString time, 
	QString DutSn, 
	int slot,
	QString state,
	QString TrayTimeId,
	double TestX,
	double TestY,
	double TestR1,
	double TestR2,
	double StdX,
	double StdY,
	double StdR1,
	double StdR2,
	std::ofstream& outFile, QString filePath)
{
	int dotNum = 4;
	outFile << time.tostr() << ','
		<< DutSn.tostr() << ','
		<< slot << ','
		<< state.tostr() << ','
		<< TrayTimeId.tostr() << ','
		<< TestX << ','
		<< TestY << ','
		<< TestR1 << ','
		<< TestR2 << ','
		<< StdX << ','
		<< StdY << ','
		<< StdR1 << ','
		<< StdR2 << ','
		<< Round_off(TestX-StdX, dotNum) << ','
		<< Round_off(TestY-StdY, dotNum) << ','
		<< Round_off(TestR1-StdR1, dotNum) << ','
		<< Round_off(TestR1 - StdR2, dotNum) << ','
		<< Round_off(TestR1 - TestR2, dotNum) << ','
		<< std::endl;
}

void ProjectDlg::WriteSlotCoordCsvHeader(QString filePath)
{
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	outFile << QString("时间").tostr() << ','
		<< QString("载具ID").tostr() << ',';
	QString slot;
	for (int i = 0; i < 24; i++)
	{
		slot= QString::number(i) + "号穴位X";
		outFile << slot.tostr() << ',';
		slot = QString::number(i) + "号穴位Y";
		outFile << slot.tostr() << ',';
	}
	outFile << std::endl;
	outFile.close();
}

void ProjectDlg::WriteSlotCoordCsvData(QString time,
	QString TrayTimeId,
	double CoorX[],
	double CoorY[],
	QString filePath)
{
	std::ofstream outFile;
	outFile.open(filePath.tostr(), ios::out | ios::app);
	int dotNum = 4;
	outFile << time.tostr() << ','<< TrayTimeId.tostr() << ',';
	for (int i = 0; i < 24; i++)
	{
		outFile << CoorX[i] << ','<< CoorY[i] << ',';
	}
	outFile << std::endl;
	outFile.close();
}


//void ProjectDlg::ClearFlexData(QString Path, int days)
//{
//	QFileInfoList dirinfo = GetmtfInstance()->ReadAllFileInfoFromDir(Path, "*");
//	for (auto e : dirinfo)
//	{
//		if (e.fileName() != "." && e.fileName() != "..")
//		{
//			int day, hour, minute, second;
//			QDateTime datatime = e.birthTime();
//			GetmtfInstance()->CurrentTimeToPast(datatime, day, hour, minute, second);
//			if (day > days)
//			{
//				if (e.isDir())
//				{
//					GetmtfInstance()->deleteDir(e.absoluteFilePath());
//				}
//				else
//				{
//					e.dir().remove(e.absoluteFilePath());
//				}
//			}
//		}
//	}
//	return;
//}

void ProjectDlg::ClearFlexData(QString Path, int days)
{
	int num = 100;
	QFileInfoList dirinfo = GetmtfInstance()->ReadAllFileInfoFromDir(Path, "*");
	for (auto e : dirinfo)
	{
		if (e.fileName() != "." && e.fileName() != "..")
		{
			QString name = e.fileName();
			int day, hour, minute, second;
			QDateTime datatime = e.birthTime();
			GetmtfInstance()->CurrentTimeToPast(datatime, day, hour, minute, second);
			//if (1)
			if (day > days)
			{
				if (e.isDir())
				{
					QString path = e.absoluteFilePath();
					while(true)
					{
						QString path2 = e.absoluteFilePath();
						int res = GetmtfInstance()->deleteDir(e.absoluteFilePath(), num);
						if (res == -1)
							mSleep(2000);
						else
							break;
					}
				}
				else
				{
					e.dir().remove(e.absoluteFilePath());
				}
			}
		}
	}
	return;
}

void ProjectDlg::CleanUpRubbishDocuments()
{
	auto fun = [=] {
		LOG_DEBUG(glogger, MultUtf82Mult2("----------------清理过期文件开始---------》"));
		ClearFlexData(m_PictureFolderPath, m_Days);
		ClearFlexData(m_PlcLogDataFolderPath, m_Days);
		ClearFlexData(m_WorkRateFolderPath, m_Days);
		ClearFlexData(m_CsvFolderPath, m_Days);	
		LOG_DEBUG(glogger, MultUtf82Mult2("----------------清理过期文件结束---------！"));
	};
	gthpool->AddTask(fun);
}

void ProjectDlg::ReadWarningInfo()
{
	QString filePath = GetmtfInstance()->CreateInnerFile(0, "", "DataFile/"+gProjectFolder+"/File/WarningInfo/报警信息.csv");
	std::ifstream inFile(filePath.tostr(), std::ios::in);
	if (!inFile.is_open())
	{
		//log("报警数据加载失败！");
		LOG_DEBUG(glogger, MultUtf82Mult2("报警数据加载失败！"));
		return;
	}
	std::string lineStr;
	while (getline(inFile, lineStr))
	{
		if (lineStr.empty())
		{
			continue;
		}
		std::stringstream ssline(lineStr);
		std::string str;
		int warningNum = -1;
		while (getline(ssline, str, ','))
		{
			if (isDigitStr(toqstr(str)))
			{
				warningNum = toqstr(str).toInt();
			}
			else
			{
				m_WarningMap[warningNum] = toqstr(str);
			}
		}
	}
	inFile.close();
	return;
}

void ProjectDlg::InitLight()
{
	try
	{
		if (Pgv::getNameControlMap()[CTRL_NAME_0] != nullptr)
		{
			Pgv::getNameControlMap()[CTRL_NAME_0]->SetWorkMode(1);//（0 代表常亮模式，1 代表常用触发模式）
			Pgv::getNameControlMap()[CTRL_NAME_0]->SetTriggerActivation(0,3);//[0-3]（0 代表跟随正触发，3 代表上升沿触发）			
			int channel[4] = {1,2,3,4};
			int time[4] = {200,200,200,200 };
			Pgv::getNameControlMap()[CTRL_NAME_0]->SetMultiTriggerWidth(channel, time,4);
		}
		for (auto i = 0; i < m_LightIntensity.size() - 2 && Pgv::getControlNum() != 0; i++)
		{
			if (Pgv::getNameControlMap()[CTRL_NAME_0] != nullptr)	Pgv::getNameControlMap()[CTRL_NAME_0]->SetIntensity(m_vecLightChannel.at(i), m_LightIntensity.at(i).P0);
			//if ((Pgv::getNameControlMap()[CTRL_NAME_0] != nullptr) && (i < 2 || !m_bAlwaysBright))	Pgv::getNameControlMap()[CTRL_NAME_0]->CloseChannel(m_vecLightChannel.at(i));		
		}
	}
	catch (...)
	{
		MessageBoxTip("打开光源控制器1出错！");
	}

	try
	{
		for (auto i = 4; i < m_LightIntensity.size() - 1 && Pgv::getControlNum() != 0; i++)
		{
			if ((Pgv::getNameControlMap()[CTRL_NAME_1] != nullptr) && (i == 4))
			{
				Pgv::getNameControlMap()[CTRL_NAME_1]->SetIntensity(0, m_LightIntensity.at(i).P0);
				Pgv::getNameControlMap()[CTRL_NAME_1]->CloseChannel(0);
			}
		}
	}
	catch (...)
	{
		MessageBoxTip("打开光源控制器2出错！");
	}
}

void ProjectDlg::InitCameraPara()
{
	if (Pgv::getNameCameraMap()[CAM_NAME_0] != nullptr) 
	{
		Pgv::getNameCameraMap()[CAM_NAME_0]->SetTriggerModel("on","line0");
		Pgv::getNameCameraMap()[CAM_NAME_0]->SetTriggerSelector(6);//6:FrameBurstStart
		Pgv::getNameCameraMap()[CAM_NAME_0]->SetTriggerActivation(0);//0:RisingEdge
		Pgv::getNameCameraMap()[CAM_NAME_0]->SetTriggerOutput(1,8,3,true);//1:line1,8:Strobe  3: FrameBurstStartActive
		Pgv::getNameCameraMap()[CAM_NAME_0]->SetStrobeLineDuration();//设置线路输出持续时间,0:默认相机曝光时间

		Pgv::getNameCameraMap()[CAM_NAME_0]->m_bProcessImgFrame = true;
        Pgv::getNameCameraMap()[CAM_NAME_0]->UpdataTriggerItemFun();
		Pgv::getNameCameraMap()[CAM_NAME_0]->RegTriggerCallBackFun(TriggerCallBackFunCamera1, this);


		Pgv::getNameCameraMap()[CAM_NAME_0]->SetExposure(m_CameraPara.at(0).P0);
		Pgv::getNameCameraMap()[CAM_NAME_0]->SetGain(m_CameraPara.at(0).P1);
		Pgv::getNameCameraMap()[CAM_NAME_0]->SetGamma(m_CameraPara.at(0).P2);
	}
	if (Pgv::getNameCameraMap()[CAM_NAME_1] != nullptr)
	{
		Pgv::getNameCameraMap()[CAM_NAME_1]->SetTriggerModel("on", "line0");
		Pgv::getNameCameraMap()[CAM_NAME_1]->SetTriggerSelector(6);//6:FrameBurstStart
		Pgv::getNameCameraMap()[CAM_NAME_1]->SetTriggerActivation(0);//0:RisingEdge
		Pgv::getNameCameraMap()[CAM_NAME_1]->SetTriggerOutput(1, 8, 3, true);//1:line1,8:Strobe  3: FrameBurstStartActive
		Pgv::getNameCameraMap()[CAM_NAME_1]->SetStrobeLineDuration();//设置线路输出持续时间,0:默认相机曝光时间

		Pgv::getNameCameraMap()[CAM_NAME_1]->m_bProcessImgFrame = true;
		Pgv::getNameCameraMap()[CAM_NAME_1]->UpdataTriggerItemFun();
		Pgv::getNameCameraMap()[CAM_NAME_1]->RegTriggerCallBackFun(TriggerCallBackFunCamera2, this);

		Pgv::getNameCameraMap()[CAM_NAME_1]->SetExposure(m_CameraPara.at(1).P0);
		Pgv::getNameCameraMap()[CAM_NAME_1]->SetGain(m_CameraPara.at(1).P1);
		Pgv::getNameCameraMap()[CAM_NAME_1]->SetGamma(m_CameraPara.at(1).P2);
	}
	if (Pgv::getNameCameraMap()[CAM_NAME_2] != nullptr)
	{
		Pgv::getNameCameraMap()[CAM_NAME_2]->SetTriggerModel("on", "line0");
		Pgv::getNameCameraMap()[CAM_NAME_2]->SetTriggerSelector(6);//6:FrameBurstStart
		Pgv::getNameCameraMap()[CAM_NAME_2]->SetTriggerActivation(0);//0:RisingEdge
		Pgv::getNameCameraMap()[CAM_NAME_2]->SetTriggerOutput(1, 8, 3, true);//1:line1,8:Strobe  3: FrameBurstStartActive
		Pgv::getNameCameraMap()[CAM_NAME_2]->SetStrobeLineDuration();//设置线路输出持续时间,0:默认相机曝光时间

		Pgv::getNameCameraMap()[CAM_NAME_2]->m_bProcessImgFrame = true;
		Pgv::getNameCameraMap()[CAM_NAME_2]->UpdataTriggerItemFun();
		Pgv::getNameCameraMap()[CAM_NAME_2]->RegTriggerCallBackFun(TriggerCallBackFunCamera3, this);

		Pgv::getNameCameraMap()[CAM_NAME_2]->SetExposure(m_CameraPara.at(2).P0);
		Pgv::getNameCameraMap()[CAM_NAME_2]->SetGain(m_CameraPara.at(2).P1);
		Pgv::getNameCameraMap()[CAM_NAME_2]->SetGamma(m_CameraPara.at(2).P2);
	}
	if (Pgv::getNameCameraMap()[CAM_NAME_3] != nullptr)
	{
		Pgv::getNameCameraMap()[CAM_NAME_3]->SetTriggerModel("on", "line0");
		Pgv::getNameCameraMap()[CAM_NAME_3]->SetTriggerSelector(6);//6:FrameBurstStart
		Pgv::getNameCameraMap()[CAM_NAME_3]->SetTriggerActivation(0);//0:RisingEdge
		Pgv::getNameCameraMap()[CAM_NAME_3]->SetTriggerOutput(1, 8, 3, true);//1:line1,8:Strobe  3: FrameBurstStartActive
		Pgv::getNameCameraMap()[CAM_NAME_3]->SetStrobeLineDuration();//设置线路输出持续时间,0:默认相机曝光时间

		Pgv::getNameCameraMap()[CAM_NAME_3]->m_bProcessImgFrame = true;
		Pgv::getNameCameraMap()[CAM_NAME_3]->UpdataTriggerItemFun();
		Pgv::getNameCameraMap()[CAM_NAME_3]->RegTriggerCallBackFun(TriggerCallBackFunCamera4, this);

		Pgv::getNameCameraMap()[CAM_NAME_3]->SetExposure(m_CameraPara.at(3).P0);
		Pgv::getNameCameraMap()[CAM_NAME_3]->SetGain(m_CameraPara.at(3).P1);
		Pgv::getNameCameraMap()[CAM_NAME_3]->SetGamma(m_CameraPara.at(3).P2);
	}
}